-->
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.  [ 1 post ] 
Author Message
 Post subject: Transactions and Session
PostPosted: Mon Mar 05, 2007 10:28 am 
Beginner
Beginner

Joined: Wed Jan 31, 2007 11:39 am
Posts: 24
I have a very simple web application that uses Tomcat 5.0, Hibernate 3.2, hsqldb database, and I have the following properties in the hibernate.cfg.xml:

<property name="current_session_context_class">org.hibernate.context.JTASessionContext</property>
<property name="hibernate.transaction.manager_lookup_class"> org.hibernate.transaction.JOTMTransactionManagerLookup
</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory
</property>


I do not use EJBs (since I use Tomcat) so my hierarchy is:

JSF--> managed beans --> UserDAO.

I've managed to save in the database and retrieve data in the database. What I am doing is opening a UserTransaction and then getCurrentSession in the UserDAO. For example :

Code:
Context ctx = new InitialContext();
tx = (UserTransaction)ctx.lookup("java:comp/env/UserTransaction");
tx.begin();             
session = HibernateUtil.getSessionFactory().getCurrentSession();   
Criteria criteria = session.createCriteria(User.class);      
criteria.add(Restrictions.eq("username", username));   
criteria.add(Restrictions.eq("password", password));
List results = criteria.list();         
session.close();
tx.commit();


What I want to ask is: Should I also open a transaction, and a session in the method of the UserBean that calls the method in the DAO? What I mean is should I open a transaction, and a session in the methods in the UserBean or I am correct if I only do it in the UserDAO?

Any suggestions?? Thank you....


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

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.