• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

LAzy fetch for specific named queries in a POJO class

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic