| 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.
|
 |
 |
|
|
subject: Named query to override eager fetching
|
|
|