-
Nov 22nd, 2009, 03:45 AM
#1
Transaction mgmt - am I missing something?
Hi,
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?
Thanks
-
Nov 22nd, 2009, 10:11 AM
#2
more details
Hi,
(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
#3
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
#4
Good question - you probably know about the docs already
https://www.hibernate.org/42.html
http://static.springsource.org/sprin...on-declarative
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules