|
From: Colin S. <col...@ex...> - 2006-07-29 00:35:55
|
We need to maintain the same semantics as Hibernate here. It would introduce massive confusion if it behaved differently. And indeed, if the object is marked as lazy (to be proxied), load() from Hibernate will happily return a prox for an object which doesn't exist, throwing an exception only when you try to use the object. This was actually an unbelievably bad design decision on their part, as it makes the "throws exception on non-existence" part completely unreliable if you think somebody is going to turn on proxying for the objects, but anyway... On 7/26/2006 4:18 AM, Colin Yates wrote: > Actually, althought the javadoc doesn't explicitly mention it (and is > quite badly worded actually) load won't hit the database if your class > is proxied. This is mentioned in the reference documentation (section > 10.3) and is encapsulated in the > org.hibernate.event.def.DefaultLoadEventListener. > > Given these semantics are defined by Hibernate I am not really sure > that Spring should change the behaviour as it would quite unintuitive. > > To our original question, I believe even if the class *is* lazy > loaded, load would still hit the database to confirm identity but that > is an assumption and I haven't traced it through to verify that > behaviour. The Javadocs do make it clear that load should only be > used for known persistent objects, if in doubt, use get. > > Col > > P.S. I think I will write a couple of tests to verify this behaviour > and will get back to you. > > On 26/07/06, *Colin Yates* < col...@gm... > <mailto:col...@gm...>> wrote: > > Hi Bill, > > Hibernate3 only makes relationships lazy by default, not the > class. This is sensible (in my opinion) because most of the time > there is no real reason to load the class in seperate chunks (aka > field groups). I believe that they actually mention in their > documentation that they only support lazy loading of the class in > order to "tick a box" :) > > Also, checking out the hibernate document for the hibernate > Session ( > http://hibernate.org/hib_docs/v3/api/org/hibernate/Session.html#load(java.lang.Class,%20java.io.Serializable) > <http://hibernate.org/hib_docs/v3/api/org/hibernate/Session.html#load%28java.lang.Class,%20java.io.Serializable%29>) > indicates that the load methods *do* check that the object > exists. So hibernate will throw its HibernateException and Spring > will then convert this into one of its own DataAccessException. > > HTH. > > On 26/07/06, *Bill Six* <bil...@ya... > <mailto:bil...@ya...>> wrote: > Hi, > > I have a question about the load() methods on > hibernate3's HibernateTemplate. > > Spring's javadoc for load() say that an exception will > be thrown if the object is not found. However, from > what I understand, Hibernate 3 changed its default > behavior to lazy load all classes. This means that if > you try to load an object with an ID that does not > exist, a Hibernate error is not thrown because you get > a proxy to the object that does not exist. It is only > upon the first method call to that proxy that > Hibernate's ObjectNotFoundException is thrown. I > would think that in Spring's load() methods should > force initilization of that object so that trying to > load an object that does not exist immediately throws > the correct Spring exception. > > I have attached a patch that should do the trick. I > have never made a patch before, nor have I ever looked > through the source of spring or hibernate, so please > excuse any stupid mistakes :-) > > Thanks for a great product, > > Bill Six > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys -- and earn > cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> > > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > <mailto:Spr...@li...> > https://lists.sourceforge.net/lists/listinfo/springframework-developer > <https://lists.sourceforge.net/lists/listinfo/springframework-developer> > > > > > >------------------------------------------------------------------------ > >------------------------------------------------------------------------- >Take Surveys. Earn Cash. Influence the Future of IT >Join SourceForge.net's Techsay panel and you'll get the chance to share your >opinions on IT & business topics through brief surveys -- and earn cash >http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > >------------------------------------------------------------------------ > >_______________________________________________ >Springframework-developer mailing list >Spr...@li... >https://lists.sourceforge.net/lists/listinfo/springframework-developer > > |