persistence@glassfish.java.net

Safe DDL generation with injection

From: Klaus Unger <UngerKlaus_at_gmx.de>
Date: Thu, 29 Nov 2007 22:40:59 +0100

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