Hi !
I have a problem with transactions that does not rollback as expected. I'm using Hibernate with JTA inside a Jonas container.
I have several transactions done in the same hibernate session. If a transaction rollback and the next one commit, both are commited !
In the following example reproducing the problem, I use JTA transaction demarcation (but the problem also exists with CMT transaction demarcation) :
Code:
/**
* @ejb.interface-method
* view-type = "local"
* @ejb.transaction
* type = "RequiresNew"
*/
public void makeTransaction(boolean rollBack, String name, String lname, SiteH site) throws Exception
{
Session session = HibernateUtil.currentSession().getSession();
Transaction hibernateTransaction = session.beginTransaction();
PersonalDetailH test = new PersonalDetailH(name, lname, Boolean.FALSE, site);
session.save(test);
if (rollBack)
{
hibernateTransaction.rollback();
throw new Exception("exception");
}
else
hibernateTransaction.commit();
}
/**
* @ejb.interface-method
* view-type = "remote"
* @ejb.transaction
* type = "Never"
*/
public void testTransactionsRollBack() throws Exception
{
try
{
SessionMoneyTestLocal thisSession = (SessionMoneyTestLocal)sessionContext.getEJBLocalObject();
SiteH site = SiteH.getEx(new Integer(3));
try {
thisSession.makeTransaction(false, "NO ROLL BACK", "1", site);
} catch (Exception e) {}
try {
thisSession.makeTransaction(true, "ROLL BACK !!", "2", site);
} catch (Exception e) {}
try {
thisSession.makeTransaction(true, "ROLL BACK !!", "3", site);
} catch (Exception e) {}
try {
thisSession.makeTransaction(false, "NO ROLL BACK", "4", site);
} catch (Exception e) {}
try {
thisSession.makeTransaction(true, "ROLL BACK !!", "5", site);
} catch (Exception e) {}
try {
thisSession.makeTransaction(false, "NO ROLL BACK", "6", site);
} catch (Exception e) {}
try {
thisSession.makeTransaction(true, "ROLL BACK !!", "7", site);
} catch (Exception e) {}
}
finally
{
HibernateUtil.closeSession();
}
}
database state: Before calling testTransactionsRollBack :
Code:
saga_celine_money=# select first_name, last_name from personal_detail where site_id=3 order by id;
first_name | last_name
------------+-----------
(0 rows)
After calling testTransactionsRollBack :
Code:
saga_celine_money=# select first_name, last_name from personal_detail where site_id=3 order by id;
first_name | last_name
--------------+-----------
NO ROLL BACK | 1
ROLL BACK !! | 2
ROLL BACK !! | 3
NO ROLL BACK | 4
ROLL BACK !! | 5
NO ROLL BACK | 6
(6 rows)
Expected database state after call :
Code:
saga_celine_money=# select first_name, last_name from personal_detail where site_id=3 order by id;
first_name | last_name
--------------+-----------
NO ROLL BACK | 1
NO ROLL BACK | 4
NO ROLL BACK | 6
(3 rows)
Hibernate version:
3.1.3
EJB container
JONAS 4.7.3
database:
PostgreSQL, version: 8.1.3
Can anyone else confirm this ?
Regards.