users@glassfish.java.net

Re: Transaction problem when persisting Entity class

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Mon, 19 Oct 2009 15:08:54 -0700

If B has a container-managed PersistenceContext, why do you get an exception
that mentions an EntityTransaction?

The transaction is started in onMessage in your bean A, so it'll be finished
when this method returns (unless you mark the method in bean B as
TransactionAttributeType.REQUIRES_NEW). Until the data is committed, it can't be
accessed by another transaction.

Also, if ejbTimeout fails, there will be a message in the log, but no client
will receive any exception. A failed timeout will be retried (at least once, but
you can change the number of retries and the delay), so if it's a timing issue -
the 2nd retry should succeed, unless onMessage logic takes really long time.

Regards,
-marina

glassfish_at_javadesktop.org wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>