File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Named query to override eager fetching Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Named query to override eager fetching" Watch "Named query to override eager fetching" New topic
Author

Named query to override eager fetching

Michael Freake
Greenhorn

Joined: Jun 03, 2009
Posts: 24
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.

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes it is.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Michael Freake
Greenhorn

Joined: Jun 03, 2009
Posts: 24
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

Joined: Jun 03, 2009
Posts: 24
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

Joined: Jun 03, 2009
Posts: 24
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Named query to override eager fetching