jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA Relational Mapping" Watch "JPA Relational Mapping" New topic

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
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
How about,


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
It's not a secret anymore!