• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPA transaction rollback fails with call to stateless bean

 
Jochem Pim
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside an UserTransaction I call a method on another stateless EJB. When I rollback this transaction, the entity created in the EJB method is not rolled back. I use EJB 3.1 with JPA 2.0. The transaction begins in doTheTransaction():

The RandomEJB:

To be complete, here is the essential part of SomeEntity:

If you are interested, this is my persistence.xml:


Why is the entity created in RandomEJB not rollback, while the entity created directly inside the transaction is?
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was reading a book yesterday and it says that when you use this @TransactionManagement(TransactionManagementType.BEAN) , your transaction is not propagated, even if you rollback, when you call the other EJB, it will suspend your transaction and start a new one.

I think that is what is happening here.
 
Jochem Pim
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hebert Coelho wrote:I was reading a book yesterday and it says that when you use this @TransactionManagement(TransactionManagementType.BEAN) , your transaction is not propagated, even if you rollback, when you call the other EJB, it will suspend your transaction and start a new one.

I think that is what is happening here.

You are right. Removing this:

from RandomRJB resolves the problem.
 
lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was reading a book yesterday and it says that when you use this @TransactionManagement(TransactionManagementType.BEAN) , your transaction is not propagated

Even, I was looking at the specs and searching around in the internet regarding this tx propagation. However, I could not find any such clear information. Can you please let us know which book you are referring to?

Thanks,
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lokesh chenta wrote:Hi,

I was reading a book yesterday and it says that when you use this @TransactionManagement(TransactionManagementType.BEAN) , your transaction is not propagated

Even, I was looking at the specs and searching around in the internet regarding this tx propagation. However, I could not find any such clear information. Can you please let us know which book you are referring to?

Thanks,


Sure, It is the Pro EJB 3, Mike Keith and Merrick Schinca, Page 58
 
lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the effort Hebert. I actually didnt understand the complete scenario. And was looking at only calls to beans with CMT from inside a BMT bean.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the case of this post, it is using a @TransactionManagement(TransactionManagementType.BEAN).

If it calls another beans the current transaction will be suspended and another one will exists.

I believe that the same rules applies to BMT calling CMT.

Because, in the case of this post, the user has a committed entity and a rollback action that is not working.

That is why I believe that this rule is being applied to BMT calling CMT.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hebert,

BMT method to CMT method behaves differenly based on TransactionAttributes used,

Required-->bean transaction will be carried over to CMT managed method since transactional context is available, if not, it will create newly
RequiredNew--> always create new transaction. So, here BMT is suspended and cannot keep the track of "RequiredNew" method
Mandatory--> same as "Required" scenario...if no transactional context i.e., calling this type method without no transaction in line, exception will be thrown

Likewise, it varies for Supported, NotSupported and Never


In turn, CMT to BMT,

CM Transaction will be suspended and BMT method will be invoked without any transactional context. So, BM transactions will be within the business logic code boundary...
So, committed BM Transaction cannot be rolled back when doing Rollback of CMT since CMT does not have the trace of transactions made in BMT managed method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!