-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to handle Hibernate Transaction in struts execute()?
PostPosted: Mon Sep 14, 2009 11:40 am 
Newbie

Joined: Mon Sep 14, 2009 11:35 am
Posts: 1
Lets say, we need to do a couple of save/updates on different objects inside struts Action's execute(). What is the best way to handle Hibernate Transaction in the execute()?
If we want it as an atomic operation, should we create the transaction in the beginning of the execute() and commit it at the end? If we do that, we have to pass this transaction object to all the DAO's methods as an argument. Just want to see what is the best approch for this? Appreciate any help. Thanks!


Top
 Profile  
 
 Post subject: Re: How to handle Hibernate Transaction in struts execute()?
PostPosted: Mon Sep 14, 2009 6:04 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Nope, no need to pass the transaction object to the DAO. That's a nasty anti-pattern.

The most common approach, and simplest, is the open session in view type of approach, where the transaction is started as soon as the request comes in, and committed just before the response goes out. The tx context is automatically passed to the DAO objects through the transactional context. It's all very nifty!

Here's a little tutorial I put together on using advanced DAOs. It applies to Struts, but I think I just demonstrate with simple Servlet and JSP apps:

http://jpa.ezhibernate.com/Javacode/lea ... vanceddaos

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.