users@glassfish.java.net

Re: Entity Manager transaction synchronization

From: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>
Date: Mon, 08 Dec 2008 15:36:33 -0800

glassfish_at_javadesktop.org wrote:
> I thought an application managed entity manager automatically synchronizes with a JTA transaction only if it is created inside the transaction.
>
> However, if I create the entity manager inside the post construct method of a stateless session bean, it is synchronized with the transaction that is started when the first call of a business method is performed (it isn't synchronized with the transactions of the following calls of a business method).
>
> Is this behavoir intended ?
I would consider the behavior of joining a transaction when user
application has not explicitly called joinTransaction() a bug.

However, IIUC, you are trying to cache em reference inside a SLSB in
@PostConstruct. You might get undefined behavior if this em is reused by
container across transactions. Please note that creation of em is a
light weight operation. You can create em inside your business methods
on demand. This would make your code easier to maintain and would work
around this issue.

Thanks,
Mitesh
> Are there other situations where an application managed entity manager unexpectedly synchronizes with a transaction ?
>
> Thanks for your information.
> [Message sent by forum member 'ralph_jaus' (ralph_jaus)]
>
> http://forums.java.net/jive/thread.jspa?messageID=320407
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>