• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to open a new hibernate transaction with ejb3?

 
Liwuen Chew
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody! I have a simple but annoying question . How can I make (or call for) a new transaction when running along all the hibernate process?

What I mean is the following. I have a web service running with Jboss and Hibernate (using ejb3). The thing is that I want to make 5 inserts, but for example if the no. 3 fails, the first two are rollbacked automatically and the last two are not even persisted. I always get a "EntityManager must be access within a transaction" exception, so I found that the problem was that I was using the same transaction along all the 5 inserts.

I have 5 methods (one per each insert), and I was using the annotation "@TransactionAttribute(TransactionAttributeType.SUPPORTS)" in everyone of them. I changed them to "@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)" on each one, but the problem persists. Does anyone know what should I change to get the non-fail inserts to not roll back? Thanks!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a Hibernate problem really. Hibernate will use the transaction it is running in if CMT is being used - it can't really do anything else. Assuming you've got a CMT method that is annotated with requires new and you call it five times the transactions will not effect each other.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic