-
1. Re: Silly (maybe not ;) ) question about rollback CMT
martinganserer Nov 28, 2005 7:17 AM (in response to jacekolszak)Hello,
you have to throw a new RuntimeException() to rollback a CM transaction! -
2. Re: Silly (maybe not ;) ) question about rollback CMT
jacekolszak Nov 28, 2005 7:35 AM (in response to jacekolszak)"martin ganserer" wrote:
Hello,
you have to throw a new RuntimeException() to rollback a CM transaction!
Hm... yes.. I know... But is this only one possible way ? When i throw RuntimeException my CMB will be removed from pool :(
Look at this... :
@Statefull
class Abc {
public void method1(){
// some operations on db
}
public void rollback(){
throw new RuntimeException()
}
}
I have a client which want to rollback last update for example. So it executes rollback method and then throw runtime exception. Do you know other possible ways ?
Regards
Jacek -
3. Re: Silly (maybe not ;) ) question about rollback CMT
martinganserer Nov 28, 2005 7:40 AM (in response to jacekolszak)Hi,
I am not sure if it helps but what's about UserTransactions?
By using them you don't have to throw a RuntimeException. You can or must use commit and rollback. -
4. Re: Silly (maybe not ;) ) question about rollback CMT
jacekolszak Nov 28, 2005 7:49 AM (in response to jacekolszak)"martin ganserer" wrote:
Hi,
I am not sure if it helps but what's about UserTransactions?
By using them you don't have to throw a RuntimeException. You can or must use commit and rollback.
Thanks a lot. Now it working:@TransactionManagement(TransactionManagementType.BEAN) @Stateful public class TranBean implements TranLocal { @PersistenceContext(type = PersistenceContextType.EXTENDED) protected EntityManager em; @Resource protected SessionContext ctx; public void test() { em.getTransaction().begin(); TranEntity e = new TranEntity("Jasd"); em.persist(e); } public void test34() { em.getTransaction().rollback(); } }
-
5. Re: Silly (maybe not ;) ) question about rollback CMT
kabirkhan Nov 28, 2005 7:58 AM (in response to jacekolszak)You could keep using container managed transactions, and call SessionContext.setRollbackOnly()
-
6. Re: Silly (maybe not ;) ) question about rollback CMT
jacekolszak Nov 28, 2005 9:05 AM (in response to jacekolszak)"kabir.khan@jboss.com" wrote:
You could keep using container managed transactions, and call SessionContext.setRollbackOnly()
Ok... so using this how can I rollback transaction? (only be exception ?)
One more question - is it possible to create save points in EJB 3?
Thanks for replies
Jacek -
7. Re: Silly (maybe not ;) ) question about rollback CMT
bill.burke Nov 28, 2005 9:12 AM (in response to jacekolszak)save points? Sort of. You have to use extended persistence context and flushmode.NEVER. Basically, updates/inserts/deletes are held up until you call flush() manually.
setRollbackOnly just marks the transaction to be rolled back. YOu can also throw an Runtime, Remote, or an exception marked with @ApplicationException(rollback=true) to automatically rollback the tx. -
8. Re: Silly (maybe not ;) ) question about rollback CMT
jacekolszak Nov 29, 2005 4:33 AM (in response to jacekolszak)Ok... I've created bean which can begin, commit and rollback transaction. But now I'm trying to use other CMB from it.
em.getTransaction().begin(); TypDzial typ=new TypDzial(); typ.setNazwa("zooo"); tlocal.add(typ); em.getTransaction().commit();
p.s. TypDzial is a CMB
But this code gives me an exception:java.sql.SQLException: You cannot commit with autocommit set!
So.. I've set up autocommit property in persistence.xml to true - but this gives me another error -autocommit breaks ejb 3
Is there any way to use stateless CMB inside from BMP and not allow CMB to commit the transaction automatically ? Or i must use statefull CMB and FlushMode.NEVER ?