Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

transactions and stateless session beans

843830Jun 10 2008 — edited Jun 10 2008
I have a stateless session bean (A) that uses an EntityManager to find an Entity.
The method has @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
It does a Web Service call and validates the response. If the response is incorrect or an error occurs, an exception is thrown and the transaction is rolled back. No information about the web service call is written to the Entity.

What I wanted to do is write another stateless session bean (B) to always write the response from the Web Service call to the Entity.
I therefore created another stateless session bean with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW), find the Entity again, write the response to the entity and go back to the other stateless session bean to do the authorisation.

So far, it works. But when I go back to A, the Entity was changed by B. If I do an entityManager.refresh(entity); I get an error message during the refresh:
javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.HibernateException: this instance does not yet exist as a row in the database

If I do an entityManager.merge(entity); I get an error at the end of the transaction:
Could not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect):
javax.ejb.EJBException: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

If I don't do an update of the entity, I get the same error at the end of the transaction.

Does anyone have an idea why it doesn't work? Or how I can do the above?

I actually have 2 places where I want to do this. On the first place it works. I am now trying to do the same on the second place but it doesn't work and I don't see any difference...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 8 2008
Added on Jun 10 2008
1 comment
649 views