I made the change, but it still didn't work. It was still have the same problem (transaction rolled back, but Hibernate committed the insert). I removed the code that intentionally throwing unchecked exception, and I found that there was a message "global transaction =<false>" (see debugging messages below). Is that mean the transaction manager still thought that it was a local transaction, so it didn't issue rollback to Hibernate when there was an error?
Code:
[org.objectweb.jotm.jta] - one phase commit with resource= StandardXAConnection:
commit on prepare =<false>
is closed =<false>
this autoCommit =<true>
listeners size =<1>
next timeOut =<0>
timeOut period =<60000>
timeOut secs =<0>
transaction manager=<org.objectweb.jotm.Current@cee41f>
StandardXADataSource:
connection count=<2>
number of dead connection=<0>
dead lock max wait=<300000>
dead lock retry wait=<10000>
driver=<com.mysql.jdbc.Driver@151fe8a>
driver name=<com.mysql.jdbc.Driver>
number of *free* connections=<1>
max con=<0>
min con=<50>
prepared stmt cache size=<16>
transaction manager=<org.objectweb.jotm.Current@cee41f>
xid connection size=<1>
StandardConnectionPoolDataSource:
master prepared stmt cache size=<2>
prepared stmt cache size =<16>
StandardDataSource:
driver=<com.mysql.jdbc.Driver@151fe8a>
url=<jdbc:mysql://localhost:3306/my_app?useUnicode=TRUE&characterEncoding=UTF8>
user=<root>
CoreDataSource :
debug =<false>
description =<null>
login time out =<60>
user =<root>
verbose =<false>
StandardXADataSource:
connection count=<2>
number of dead connection=<0>
dead lock max wait=<300000>
dead lock retry wait=<10000>
driver=<com.mysql.jdbc.Driver@151fe8a>
driver name=<com.mysql.jdbc.Driver>
number of *free* connections=<1>
max con=<0>
min con=<50>
prepared stmt cache size=<16>
transaction manager=<org.objectweb.jotm.Current@cee41f>
xid connection size=<1>
StandardConnectionPoolDataSource:
master prepared stmt cache size=<2>
prepared stmt cache size =<16>
StandardDataSource:
driver=<com.mysql.jdbc.Driver@151fe8a>
url=<jdbc:mysql://localhost:3306/my_app?useUnicode=TRUE&characterEncoding=UTF8>
user=<root>
CoreDataSource :
debug =<false>
description =<null>
login time out =<60>
user =<root>
verbose =<false>
StandardXAConnectionHandle:
global transaction =<false>
is really used =<false>
this autoCommit =<true>
in use size =<0>
master prepared stmt cache size =<2>
transaction =<null>
connection =<com.mysql.jdbc.Connection@1e45e3>
com.mysql.jdbc.Connection@1e45e3
2007-04-20 10:31:44,096 DEBUG [org.enhydra.jdbc.xapool] - StandardXAConnection:commit perform a commit
2007-04-20 10:31:44,096 DEBUG [org.enhydra.jdbc.xapool] - StandardXADataSource:getConnection (xid=bb14:38:40:013511112e87c160fb...701003:013511112e87c160fbbf6...000000, mustFind=true)
2007-04-20 10:31:44,096 DEBUG [org.enhydra.jdbc.xapool] - XID: StandardXAStatefulConnection:
commit on prepare =<false>
timed out =<false>
id =<2>
state =<0>
time out =<0>
xid =<bb14:38:40:013511112e87c160fb...701003:013511112e87c160fbbf6...000000>
The following is my latest Spring configurations related to datasource & transaction:
Code:
<bean id="innerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">
<property name="transactionManager">
<ref local="jotm"/>
</property>
<property name="driverName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/my_app?useUnicode=TRUE&characterEncoding=UTF8</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value></value>
</property>
</bean>
<bean id="dataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
<property name="dataSource"><ref local="innerDataSource"/></property>
<property name="maxSize"><value>5</value></property>
<property name="minSize"><value>2</value></property>
<property name="user"><value>root</value></property>
<property name="password"><value></value></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>Role.hbm.xml</value>
<value>User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.query.substitutions">true=1 false=0</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="jtaTransactionManager">
<bean id="transactionManager.transactionManager" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
</property>
</bean>
<bean id="userDAO" class="UserDAOImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="userFacadeImpl" class="UserFacadeImpl">
<property name="userDAO">
<ref bean="userDAO"/>
</property>
</bean>
<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction">
<ref local="jotm"/>
</property>
</bean>
<bean id="userFacade" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="target">
<ref local="userFacadeImpl"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="addGeneralUser">
PROPAGATION_REQUIRED
</prop>
</props>
</property>
</bean>
I wonder if you can spot anything wrong with the configurations. Thanks alot, once again.