aspose file tools
The moose likes Object Relational Mapping and the fly likes RollbackException and PersistentContext Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "RollbackException and PersistentContext" Watch "RollbackException and PersistentContext" New topic
Author

RollbackException and PersistentContext

ved gunjan
Ranch Hand

Joined: May 17, 2003
Posts: 86
Hi Experts,
Im using injected persistent context in my session bean.
@PersistentContext(unit="AppConext")
private EntityManeger entityManager;

In this session bean i've a method in which,i iterate over the list.
Lets say this method as method1();
The scenario is somthing like this..
@TransactionAttribute(REQUIRES_NEW)
public voic method1()
{
......some code.....
for(SomeObject obj : someObjectList)
{
..............some code....
//call method2
method2(obj);
.........some code......
}
}

@TransactionAttribute(REQUIRES_NEW)
public void method2()
{
}

What is happening here is when i call mehod2 and pass value to it from list,
the method throws NoEntityFound excexption and ejb transaction rolls back.
In the catch block of method2 , i'm catching NoEntityFoundException and getting the programm flow to normal flow.
Throwing of NoEntiyFound exception is an expected behaviour.
But my requirement is that i need to continue the iteration over the other values in the list.

But when the programm comes back to method1 and the moment it does some
procesing i get an EJbTransactionRollBack exceptions , saying generice JDBC exception..cannot open connection..session close....

javax.transaction.RollbackException: Already marked for rollback, tx=TransactionImpl:XidImpl[FormatId=257,

1)What is the technical reson behind exception in method1?
2)What should i do to solve it so that my code processes the rest of the elements in the list?

Thanking in advance for any help.

Thanks
Vedgunjan
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17224
    
    1

First, I am going to move this to the ORM forum where we post JPA questions.

Second, it is all about what is in the spec. Unfortunately, whenever any exception is thrown, it is a subclass of RuntimeException, and if considered a "fatal" exception, meaning, as you see, the transaction set to rollback. At that time you can no longer use the EntityManager.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: RollbackException and PersistentContext
 
Similar Threads
EJB3 transction management Requires_new attribute
Enthuware question doubt
Puzzling Transactions.....
Java Beat Question - Q on transaction attributes
exception declaration