jQuery in Action, 2nd edition*
The moose likes Object Relational Mapping and the fly likes LAzy fetch for specific named queries in a POJO class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "LAzy fetch for specific named queries in a POJO class" Watch "LAzy fetch for specific named queries in a POJO class" New topic
Author

LAzy fetch for specific named queries in a POJO class

akhil achuthan
Ranch Hand

Joined: Mar 29, 2006
Posts: 69
Is it possible to define lazy fetch for specific named queries in an entity POJO. I mean i have a Person table with a one-to-many mapping defined on to other tables. Eg: For my UI which lists only the names of all the Person rows, I just need the name of all the person entries and feel that I need not fetch the entire column contents of the table along with the data of whatever mapped children tables it has. I mean all my named queries that I have defined in my JPA Pojo should return me the entire object with child values as well, except this specific query alone.

Thanks in advance
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
I would recommend making the relationships LAZY always, then using a JOIN FETCH to fetch them eagerly when required.
In general LAZY allows the relationship to only be fetched when required.

You can also execute a query that only selects the names, if all you want is the names.
i.e.


If you are using EclipseLink there is also support for fetch groups, that allow you to specify through query hints exactly what you wish to be fetched in the object.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
 
 
subject: LAzy fetch for specific named queries in a POJO class