Ram
Ram

Reputation: 15

transaction is not getting roll backed with jta transaction manager

I am new to Spring and hibernate please help,

I am using (Jboss 6.0 Final as Server)

org.springframework.transaction.jta.JtaTransactionManager

as bean with properties set

transactionManagerName as java:/TransactionManager and

userTransactionName as java:comp/UserTransaction.

In code I have set

jtaTxManager
property thr setters.

Then

javax.transaction.TransactionManager tx = jtaTxManager.getTransactionManager();

and then transaction is started using

tx.begin()
statement.

I have used

sessionFactory.getCurrentSession()  
to get session of hibernate

at last I have used

tx.commit() 

I am using hibernate to save multiple records within jta transaction but If in between any database error occurs between some record like constraint violation exception getting thrown on tx.commit() which is

javax.transaction.RollbackException
which when catch I used to call tx.rollback() but my transaction is not getting rollback and getting following exception on tx.rollback().I have not set any type auto commit property in hibernate properties.

But my first of records in gets saved in database ideally they should not saved but while rollback this exception occurs so i think that's why they are getting saved.

java.lang.IllegalStateException: BaseTransaction.rollback - [com.arjuna.ats.internal.jta.transaction.arjunacore.notx] [com.arjuna.ats.internal.jta.transaction.arjunacore.notx] no transaction!
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.rollback(BaseTransaction.java:158)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.rollback(BaseTransactionManagerDelegate.java:114)

Upvotes: 0

Views: 3247

Answers (2)

Ram
Ram

Reputation: 15

This issue was due to datasource configuration, forgot to mentioned earlier,

Removed from application-context.xml

org.springframework.jdbc.datasource.DriverManagerDataSource

and rather than this, used jndi datasorce of jboss configured in oracle-xa-ds.xml

Upvotes: 1

Puce
Puce

Reputation: 38142

The Javadoc states that the RollbackException gets thrown when the transaction has been rolledback instead of commited - you don't have to rollback it manually in such a case, I think. http://download.oracle.com/javaee/6/api/javax/transaction/Transaction.html#commit%28%29

Upvotes: 0

Related Questions