• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Named query to override eager fetching

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm using Hibernate 3.5 and wondering if it is possible to override the eager loading specified using annotations on a class via a named query?

For example, using the classes below I'd like to use a named query to get a particular course version, it's related course and none of the courses collections.

 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is.
 
Michael Freake
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply. It would be very useful if you could provide an example using the above classes so that anyone else who visits this post, including myself, can benefit from it.

Thanks again.
 
Michael Freake
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so I found this: http://ajava.org/online/hibernate3api/org/hibernate/FetchMode.html#SELECT

However, the LAZY fetch mode is now replaced by SELECT, which specifically states that it will perform eager loading... seems like they replaced lazy loading with the exact opposite to me, but I could be wrong.
 
Michael Freake
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, it appears Paul's comment above is incorrect. After reading some documentation and other posts on similar topics, you can use a named query to cause EAGER fetching, but not to cause LAZY fetching.

So basically, my lesson is make everything lazy and use named queries when you need things fetched eagerly.
 
reply
    Bookmark Topic Watch Topic
  • New Topic