persistence@glassfish.java.net

Re: Safe DDL generation with injection

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Fri, 30 Nov 2007 08:37:19 -0500

Hello Klaus,
     An application managed EM can still participate in a JTA
transaction and use a JTA managed datasource. If an EM is created
within an active transaction then it will automatically be joined to
that transaction. If not then em.joinTransaction() can be used to home
the Em synchronized with the txn.
--Gordon

Klaus Unger wrote:
> Hi,
>
> I want to use Toplinks EntityManagerFactoryProvider.DDL_GENERATION feature in
> a safe way.
>
> I used to use
> Persistence.createEntityManagerFactory(...) / emf.createEntityManager();
> however this way I cannot use a jta-data-source (I guess because this EM is
> not containermanaged).
>
> So I wanted to move this to a SessionBean getting a EM injected by:
>
> @PersistenceContext(type=PersistenceContextType.EXTENDED, properties={
> @PersistenceProperty(name=EntityManagerFactoryProvider.DDL_GENERATION,
> value=EntityManagerFactoryProvider.DROP_AND_CREATE)
> })
>
> However I feel queasy about this because I totally loose control over the time
> of execution and I see no way to synchronize this at all. The only place I
> see to do at least some preparations is the SessionBean constructor.
>
> Is there any good way to do this?
>
> Best Regards
> Klaus
>