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.  [ 4 posts ] 
Author Message
 Post subject: Best Practices to handle transactions in web applications
PostPosted: Fri Jun 19, 2009 9:37 am 
Newbie

Joined: Fri Jun 19, 2009 9:31 am
Posts: 12
Hi everybody,
I'm new to hibernate. I'm developping a web application with apache tomcat 6 and I'm not sure about the best way to handle the database transactions in my application. Currently I'm opening a session and begin a transaction when I start processing a request and i'm closing the session when processing is finished.
Code:
   Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
   session.beginTransaction();
   [...]
   session.close();

All my classes in the application access the current session like this
Code:
   Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
   session.get( ... );
   [...]

Are there any best practices to handle transactions in web applications? Is it recommmendable to use openejb (and the annotations @TransactionAttribute) to handle the transactions?

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: Best Practices to handle transactions in web applications
PostPosted: Fri Jun 19, 2009 11:20 am 
Newbie

Joined: Mon Oct 27, 2008 2:43 am
Posts: 7
This should help:
https://www.hibernate.org/43.html

_________________
-GJ


Top
 Profile  
 
 Post subject: Re: Best Practices to handle transactions in web applications
PostPosted: Fri Jun 19, 2009 11:51 am 
Newbie

Joined: Fri Jun 19, 2009 9:31 am
Posts: 12
Thanks a lot for your answer. I read the article and come to the conclusion, that my approach is the a viable option. So I will extract my session and transaction management into a filter as described in the howto.

Nevertheless I'm a bit confused about J2EE Server and my "tomcat solution" (tomcat's faq: "Tomcat is not a full J2EE server"). When or why should a use a j2ee server - I read about pluggin openejb into tomcat... Most likely there is not THE answer for my (stupid) question ;). But are there any clues to decide weather a "need" a j2ee server or not?
To simplify my question: Let's assume you should develop a web application like a online shop. Is it reasonable to use a j2ee server?

I come to the question because I read about the "@TransactionAttribute" annotation and that seems a very "intuitive" solution for handling and managing transactions but tomcat is not a j2ee server and therefore does not support this option.


Top
 Profile  
 
 Post subject: Re: Best Practices to handle transactions in web applications
PostPosted: Fri Jun 19, 2009 11:56 am 
Newbie

Joined: Mon Oct 27, 2008 2:43 am
Posts: 7
This forum may not be the best place to get an answer.
To simply answer this, for a small web application which may not have massive scaling requirements and does not use EJBs, clustering etc., Tomcat will do.

_________________
-GJ


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.