Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Transactions in EJB (http://www.go4expert.com/forums/transactions-in-ejb-t502/)

prashantSum 11Nov2005 17:15

Transactions in EJB
 
hi all,
I am little bit confused with EJB Transactions.

What I heard is we cannot control transactions in EJB with Connection.setAutoCommint(false) and Connection.commit() and Connection.rollback();

the EJB Container Starts a Transaction , if everything goes well the transaction will be commited otherwise in the catch block we have use SessionContext.setRollbackOnly();

but I am getting different results...

I have Stateless Session Bean, Transaction is Container in managed in ejb-jar.xml and Transaction attribute required.

I am inserting two records in the same table and same database with the same connection object and when I am using SessionContext.setRollbackOnly(); in the catch block and when the second insert is throwing an exception... now the transaction is not getting rolled back i.e. the first record is being inserted.

and when I am controlling it with Connection.setAutocommit(false) and Connection.commit and Connection.rollback() in the catch block it's working fine.
i.e. when second statement throwing some exception the transaction is getting rolled back and when there is no exception the transaction is getting commited.

Does Transactions are managed in differently in different Containers.

I am using OC4J Server.

sq9today 8Mar2008 02:52

hmmm....
 
Quote:

Originally Posted by prashantSum
hi all,
I am little bit confused with EJB Transactions.

What I heard is we cannot control transactions in EJB with Connection.setAutoCommint(false) and Connection.commit() and Connection.rollback();

the EJB Container Starts a Transaction , if everything goes well the transaction will be commited otherwise in the catch block we have use SessionContext.setRollbackOnly();

but I am getting different results...

I have Stateless Session Bean, Transaction is Container in managed in ejb-jar.xml and Transaction attribute required.

I am inserting two records in the same table and same database with the same connection object and when I am using SessionContext.setRollbackOnly(); in the catch block and when the second insert is throwing an exception... now the transaction is not getting rolled back i.e. the first record is being inserted.

and when I am controlling it with Connection.setAutocommit(false) and Connection.commit and Connection.rollback() in the catch block it's working fine.
i.e. when second statement throwing some exception the transaction is getting rolled back and when there is no exception the transaction is getting commited.

Does Transactions are managed in differently in different Containers.

I am using OC4J Server.

I was thinking this the other day but being new to all of this it's still a little confusing


All times are GMT +5.5. The time now is 13:29.