Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LAzy fetch for specific named queries in a POJO class

 
akhil achuthan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic