• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB3 transction management Requires_new attribute

 
prateek pathak
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a method M1() in stateless session bean with transctional attribute Required. From M1() i hava called another method M2() of same stateless session bean having transctional attribute requires_new. M2() method inserts the record into the table. After successfull completion of M2() , control is returned to M1() but data is not yet saved into the database. I am using Requires_new attribute , so data should be saved...could anybody help me please........
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If you have something like this where method1 internally does a normal Java invocation (i.e. on the "this") then there won't be any new transaction created. Its going to behave as any other simple java call and will have no EJB semantics. You will have to do something like:




 
prateek pathak
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jaikiran
Thanks for your reply. However if i have a code something like that in my stateless ejb bean

@TransctionalAttribute(NotSupported)
method1() {

mehtod2();

}

@TransctionAttribute(manadatory)
method2() {

}

when method2() tries to persist some data i got an exception that entitymanager needs to be called within an existing transction.
This indicates that transctional attribute of method2() [mandatory] is having the effect in this scenario. So why it is not working when method2() has Requires_NEW transction.



Jaikiran Pai wrote:

If you have something like this where method1 internally does a normal Java invocation (i.e. on the "this") then there won't be any new transaction created. Its going to behave as any other simple java call and will have no EJB semantics. You will have to do something like:




 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!