File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes JPA Relational Mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA Relational Mapping" Watch "JPA Relational Mapping" New topic
Author

JPA Relational Mapping

rudresh kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 83
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

Joined: Oct 01, 2007
Posts: 553
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.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA Relational Mapping