• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

JPA transaction rollback fails with call to stateless bean

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 100
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this book on google books. It is free to access if you want. Chapter 3 talks about t
http://books.google.com.br/books?id=fVCuB_Xq3pAC&pg=PA35&hl=pt-BR&source=gbs_toc_r&cad=4#v=onepage&q&f=false
 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic