users@glassfish.java.net

Transaction problem when persisting Entity class

From: <glassfish_at_javadesktop.org>
Date: Sun, 18 Oct 2009 22:12:02 PDT

I have an application with several classes. One class (A) is a message-driven bean. When a message comes into A, it calls a stateless session bean (B), through it's BLocal interface. B has a container-managed PersistenceContext. I have several other helper classes which are called by B, to which I pass the Entity Manager on the method call, for database interactions. B implements the TimedObject interface, and as such, receives calls from the TimerService periodically. When B.ejbTimeout is called, it calls another stateless session bean (C), through it's CLocal interface. C also has a container-managed PersistenceContext and it also uses some of the helper classes (and passes it's entity manager for method calls). C retrieves a specific row from the database, updates it, and tries to write the update to the database using entityManager.persist.

The problem I'm having is that when I try to persist an instance of an Entity class (say D) from C (when B.ejbTimeout calls C.go) , it does not work. I've been trying different things. Sometimes when ejbTimeout returns, there is no error for persist(D), but the data is not stored in the database. Sometimes I get "Cannot use an EntityTransaction while using JTA" exception. Sometimes I've seen a transaction start, but not complete. After this, I cannot modify the row I'm trying to persist in D from outside GF until I exit GF.

I don't know what is going on here as I think, since C is a stateless session bean and being called from it's Local interface, that there should be no problem. However, clearly there is a problem. Would anyone shed some insight on what's going on and how to solve it?

Thanks,
Darryl
[Message sent by forum member 'darryl_m' (darryl.mocek_at_sun.com)]

http://forums.java.net/jive/thread.jspa?messageID=368396