Application of Hibernate JTA transaction

xiaoxiao2021-03-06  41

The younger brother spent three days in Hibernate JTA business, it is really a bit of sweat. The examples searched online cannot be used, and the Yava foundation that the youni brother may be too weak. I don't know if you are all transactions of JTA. The online example can be transaction with session.

Written out to prevent you from forgetting it later. Ha ha.

Since I have been trying, so now I wrote the last result, if anyone knows what the steps can be omitted, please tell me.

This is use: Tomcat Hibernate Jotm

1. Configure JOTM in Tomcat (

http://www.objectweb.org/jotm/)

First go to the above website to download JOTM. followed by

Jotm.jar, jotm_jrmp_stubs.jar, jonas_timer.jar, carol.jar, JTA-Spec1_0_1.jar

JTS1_0.jar, ObjectWeb-DataSource.jar, Xapool.jar

These JAR files are copied to: $ Tomcat_Home / Common / LIB / directory.

Copy JDBC Driver to: $ Tomcat_Home / Common / LIB / Directory.

Copy the file: carol.properties to: $ TOMCAT_HOME / COMMON / CLASSES / directory.

Here, modify the Tomcat's Server.xml configuration file.

[code]

factory

Org.ObjectWeb.jndi.DataSourceFactory

........

TYPE = "javax.transaction.usertransaction" />

factory

Org.ObjectWeb.Jotm.UserTransActionFactory

jotm.timeout

60

[/ code]

Note The above database connection pool configuration, you want to use Xapool in JOTM.

Basically, we are configured with JOTM in Tomcat.

2. Transaction configuration in hibernate.

(I think this step can be omitted, but I haven't tested it yet. Please have a test.)

In hibernate.cfg.xml

net.sf.hibernate.transaction.JTATransactionFactory net.sf.hibernate.transaction.JOTMTransactionManagerLookup java: comp / userTransaction Ok, now you can use the most common code online:

1 javax.transaction.usertransaction tx = 2 new initialContext (). Lookup ("java: comp / userTransaction); 3 tx.begin (); 45 session s1 = sf.opensession (); 6 ... 7 s1.flush (); 8 s1.close (); 9 10 ... 11 12 session s2 = sf.opensession (); 13 ... 14 s2.flush (); 15 s2.close (); 16 17 TX.COMMIT );

转载请注明原文地址:https://www.9cbs.com/read-69261.html

New Post(0)