• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA Relational Mapping

 
rudresh kumar
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
 
James Sutherland
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic