-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Why transaction is not rolledback?
PostPosted: Tue Aug 02, 2005 8:42 am 
Newbie

Joined: Tue Aug 02, 2005 7:15 am
Posts: 3
Hibernate version: 2.1.8
JBoss version: 3.2.6


Name and version of the database: Oracle 9i


As it is shown below I use Mbean and I get sessions from HibernateContext.
I have a CMT Stateless Session bean which containts two methods:
method dummySave inserts 3 records (with column KOD set to T00x, T0x and III, when x = 1,2,3) into database, while method testDummySave() invokes dummySave in loop. In database there is a unique constraint set on column KOD, so an exception occurs, when dummySave is invoked the second and next times. It means that when testDummySave() ends I expect to have in the database 3 new records with KOD set to T001, T01 and III. The problem is that I have at the and also records with KOD set to T002, T02 and T003, T03. It looks that transactions are not rolledback. What is wrong with this code? What I did wrong?


Hiberante MBean

<server>
<mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=Hibernate">
<attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute>
<attribute name="DatasourceName">java:/jakistam.datasource</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.Oracle9Dialect</attribute>
<attribute name="ShowSqlEnabled">true</attribute>
<attribute name="CacheProviderClass">net.sf.hibernate.cache.EhCacheProvider</attribute>
<attribute name="QueryCacheEnabled">true</attribute>
</mbean>

</server>



/**
*
* @ejb.interface-method view-type = "both"
* @ejb.transaction type = "RequiresNew"
*/
public void dummySave(String nazwa1, String nazwa2) {
Session session = HibernateContext.getSession("java:/hibernate/SessionFactory");

StatusSprawy statusSprawy = new StatusSprawy();
statusSprawy.setKod(nazwa1);

StatusSprawy statusSprawy2 = new StatusSprawy();
statusSprawy2.setKod(nazwa2);

StatusSprawy statusSprawy3 = new StatusSprawy();
statusSprawy3.setKod("III");

try {
session.save(statusSprawy);
session.save(statusSprawy2);
session.save(statusSprawy3);
session.flush();
} catch (HibernateException e) {
throw new EJBException(e);
}
}

/**
*
* @ejb.interface-method view-type = "both"
*/
public void testDummySave() {
String ii = null;
for (int i = 1; i <= 3; i++) {
try {
ii = String.valueOf(i);
saveTest("T00" + ii, "T0" + ii);
} catch (EJBException e) {
e.printStackTrace();
}
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 07, 2005 4:03 pm 
Newbie

Joined: Tue Aug 02, 2005 7:15 am
Posts: 3
The answer is easy: testDummySave should be in the different bean than dummySave.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 07, 2005 5:38 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 7:11 am
Posts: 85
Quote:
It looks that transactions are not rolledback. What is wrong with this code? What I did wrong?


Because dummySave method is executed in the transaction context of testDummySave and if using direct call (as you did) don't have it's own context regardless of RequiresNew attribute. If you split methods on different beans or do call through container proxy reference (SessionContext.getEJBObject), then CMT would have a chance to create new context.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.