-->
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: Transaction by JTA
PostPosted: Wed May 03, 2006 9:51 pm 
Newbie

Joined: Wed May 03, 2006 9:40 pm
Posts: 1
Hi, all
I'm troubling how to use JTA in Hibernate Transaction.
Please let me know it.
My arcitecture is below.
StrutsAction<-->StatelessSessionBean<-->Command<-->Dao(hibernate)<-->DB

I'd like to use JTA for transaction.
In this case, how should I write dao source?
Need I use 'session.beginTransaction'?

regards
hirovic

Hibernate version:
3.1.3
Mapping documents:
<?xml version="1.0" ?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<!--PostgresSQL JDBC Driver connection -->
<property name="connection.driver_class">org.postgresql.Driver
</property>
<property name="connection.url">jdbc:postgresql://***</property>
<property name="connection.username">**</property>
<property name="connection.password">**</property>
<property name="hibernate.connection.datasource">java:/**.DS</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<!-- Mapping files -->
<mapping resource="EMP.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():

Emp emp = new Emp();
emp.setEmpno(new Integer(100));
emp = (Emp)session.load(Emp.class, emp.getEmpno());
emp.setJob("Sales");
session.update(emp);


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 10:32 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Are you running your code in a JBoss container? If you are, and you've told JBoss about JTA, then no, you don't need to use session.beginTransaction(). JBoss uses JTA for application transactions, so once you have those configured, you shouldn't need to use database transactions any more.

I'm afraid I don't know how to configure JBoss to use JTA though. It's possible that what you've already done is enough, or there may be a JBoss configuration file that you have to update, too.

_________________
Code tags are your friend. Know them and use them.


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.