-
1. Re: Tryed searching for this issue, but haven't found anythi
orclev Jul 24, 2006 1:39 AM (in response to orclev)Ok. after mucking around some more I discovered something. I was using HibernateDaoSupport as my base class on my DAOs, and then using getHibernateTemplate() to perform the load operation on my entity bean. When I changed to just using getSession() the problem went away. Not sure why exactly it's working like that, but maybe it will give some clue as to what I'm doing wrong.
-
2. Re: Tryed searching for this issue, but haven't found anythi
epbernard Jul 25, 2006 6:34 PM (in response to orclev)This is exactly why Spring templates are evil. They wrap a one line of useful code (duh), and hide the actual Hibernate JavaDoc explaining the difference between get() and load()
load return a lazy object. Use get most of the time -
3. Re: Tryed searching for this issue, but haven't found anythi
tobias Jul 26, 2006 5:45 AM (in response to orclev)Could you please point me to the JavaDoc that explains the differences between load() and get() concerning getting proxies or the "real" instances?
I couldn't find it in http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Session.html. -
4. Re: Tryed searching for this issue, but haven't found anythi
robjellinghaus Jul 26, 2006 12:27 PM (in response to orclev)A very close reading of the Javadoc does yield some differences:
get - Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. Obtain the specified lock mode if the instance exists. Returns: a persistent instance or null
load - Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. You should not use this method to determine if an instance exists (use get() instead). Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error. Returns: the persistent instance or proxy
I agree it's pretty subtle though.
The Hibernate reference doc http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#objectstate-loading is a little more clear:
"Note that load() will throw an unrecoverable exception if there is no matching database row. If the class is mapped with a proxy, load() just returns an uninitialized proxy and does not actually hit the database until you invoke a method of the proxy."
Cheers!
Rob[/url] -
5. Re: Tryed searching for this issue, but haven't found anythi
robjellinghaus Jul 26, 2006 12:39 PM (in response to orclev)Also, great blog post here: http://www.sleberknight.com:8080/roller/comments/sleberkn/Weblog/using_spring_with_hibernate3_s
Cheers again!
Rob -
6. Re: Tryed searching for this issue, but haven't found anythi
gavin.king Jul 26, 2006 12:51 PM (in response to orclev)How is it a great blog post when the guy totally missed the entire reason why load() behaves like it does?
The Hibernate distinction between load() and get() is just like the JPA distinction between getReference() and find(). You need both options. -
7. Re: Tryed searching for this issue, but haven't found anythi
dserodio Jul 26, 2006 3:19 PM (in response to orclev)"gavin.king@jboss.com" wrote:
How is it a great blog post when the guy totally missed the entire reason why load() behaves like it does?
Wouldn't it help if you added the "reason why load() behaves like it does" to the Session javadocs? -
8. Re: Tryed searching for this issue, but haven't found anythi
epbernard Jul 26, 2006 5:57 PM (in response to orclev)In the Hibernate reference documentation
Note that load() will throw an unrecoverable exception if there is no matching database row. If the class is mapped with a proxy, load() just returns an uninitialized proxy and does not actually hit the database until you invoke a method of the proxy. This behaviour is very useful if you wish to create an association to an object without actually loading it from the database. It also allows multiple instances to be loaded as a batch if batch-size is defined for the class mapping.
-
9. Re: Tryed searching for this issue, but haven't found anythi
dserodio Jul 26, 2006 6:00 PM (in response to orclev)"epbernard" wrote:
In the Hibernate reference documentation...
I see that the reference documentation (which is great, BTW) contains this info, but would it hurt to add it to the javadoc too? -
10. Re: Tryed searching for this issue, but haven't found anythi
gavin.king Jul 26, 2006 6:01 PM (in response to orclev)Emmanuel, that's just silly. You can't reasonably expect people to actually read freely-available documentation about something before blogging it to the world.
;-) -
11. Re: Tryed searching for this issue, but haven't found anythi
dserodio Jul 28, 2006 11:02 AM (in response to orclev)dserodio wrote:
epbernard wrote:
In the Hibernate reference documentation...
I see that the reference documentation (which is great, BTW) contains this info, but would it hurt to add it to the javadoc too?"gavin.king@jboss.com" wrote:
Emmanuel, that's just silly. You can't reasonably expect people to actually read freely-available documentation about something before blogging it to the world.
;-)
I'll take that as a "no, we need something to slap newbies-who-don't-RFTM with".
In case you didn't notice, I posted a constructive comment, not a rant. -
12. Re: Tryed searching for this issue, but haven't found anythi
epbernard Jul 28, 2006 3:08 PM (in response to orclev)There is a reason for not adding common usages into the JavaDoc. We would en up having very long JavaDocs (ie Reference guide in it), so we decided to not include usages.
-
13. Re: Tryed searching for this issue, but haven't found anythi
vikasphonsa Oct 30, 2006 12:11 PM (in response to orclev)I'm a newbie to hibernate 3 (haven't worked with older versions) and this discussion did help me understand the difference between get() and load().
Is there any reason to favor one method over the other, besides the application specific considerations ?
Is any of the two methods there just for backward compatibility or other reasons ?
Thanks in advance.
Vikas