Nov 22nd, 2009, 03:45 AM
Transaction mgmt - am I missing something?
I'm developing a spring/struts2/hibernate app, and deploying on tomcat.
I'm using tx:annotation-driven, and marking my service methods with @Transactional. I was under the impression that this is binding me to a sesion context. in one of my service methods, I have some persistent object (which was retrieved from a dao, using an injected session factory), but when I'm accessing a collection, I still get the hibernate lazy instansiation exception (no session or session was closed). do I need to do anything else to have a session to work with?
Nov 22nd, 2009, 10:11 AM
(moderator, you can delete the root post and put this one instead)
My problem now is a little more focused.
I'm using annotation driven transactions. I have a transactional service method, which accept a dettached object from the fromt end.
if I'm using session.merge to re-attache my object, I get a lazy instantiation exception when asking a 'lazy' collection.
If I'm re-reading the object by Id, everything seems to work.
does this behaviour make sense?
Thanks in advance
Nov 23rd, 2009, 10:05 AM
See session in view pattern
Not sure about exact problem you are facing, but I will recommend you to google for "Session In View" pattern, to overcome with lazy init and detached objects problems.
Nov 23rd, 2009, 08:26 PM
Good question - you probably know about the docs already
But try using the OpenSessionInViewFilter
http://static.springsource.org/sprin...iewFilter.html -- google for configuration details, it's just a filter in your web.xml that attaches the HBM session as a threadlocal, as I recall, and closes after Filter processing is complete. Seems to work for most people, but I am not sure how well it behaves well with JTA. Having issues there myself.