This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Named query to override eager fetching  RSS feed

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is.
 
Michael Freake
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!