Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

JPA Relational Mapping

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a question on retrieving the entities from JPA

Consider a employee entity



Dept Entity



If i have an dept id and want to get all employees, the only option i see is


This will fire two queries, one on the dept and then on employees (lazy loading)
But i am interested only in employees, there are no options in jpa to get this even using query (as there are no dept id in employee object). The reason i am asking is, when i am interested only in Employee, why to query Dept (what if it has 100's of more attributes which are not relevant).

Kindly let me know if this is the only way to resolve.

Thanks in advance
Rudresh
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about,



or,



Of coarse if the Department was already in the cache, the find on it and access to its employees would be the most efficient way to access the employees.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!