Hibernate version: 3.2.CR2
Hibernate annotations: 3.2.0.CR1
Hibernate EntityManager 3.2.0.CR1
Is there a way to create DDL using SchemaExport and still be able to use a 'vanilla' EntityManagerFactory?
Let me explain the question:
I need to be able to generate DDL for my persistent classes using EJB3. I understand that the EJB3 specification pretty much ignores this need
and that I have to delve into implementation-specific services, however I'm having an issue with how I had to go about this.
I've discovered that, if I want to use Hibernate's SchemaExport class to do this generation, I have to create the EntityManagerFactory using
the EJB3Configuration class rather than javax.persistence.Persistence. e.g.
EJB3Configuration ejb3Config = new Ejb3Configuration(); // get EJB3 config
EntityManagerFactory emf = ejb3Config.createEntityManagerFactory(PERSISTENCE_UNIT, configOverrides); // create EMF for use with DDL work.
This means I have two choices:
1. Create two EntityManagerFactories - one created using javax.persistence.Persistence.createEntityManagerFactory(),
the other created using the EJB3Configuration class.
2. Create one EntityManagerFactory using the Ejb3Configuration.
The first option is why carry two? - I'm now having to carry two EMFs: one for DDL generation and one for DML work - that seems a bit wasteful.
The second option has a problem in that I'm having to pull in implementation-specific code to support my DML work - I'd expect that of the DDL
work - since the specification ignores that but not the DML work.
I was striving to keep the DML side of the house as generic as possible, but, with the requirement of creating DDL, I've had to compromise the
design and de-partition some of the logic.
I also tried creating an EJB3Configuration on the fly and using a javax.persistence.Persistence created EntityManagerFactory, but, alas, this
did not work - for SchemaExport to work - an EntityManagerFactory has to be created from the EJB3configuration before that configuration can
be used to create the DDL.
So - my question then - is there some what to provide DDL creation capabilities using the hibernate implementation of EJB3 and still use an
EntityManagerFactory created using javax.persistence.Persistence.createEntityManagerFactory();
I apologise for the long ramble - but it strikes me that surely the javax.persistence.Persistence.createEntityManagerFactory() call could be
doing the work that the EJB3Configuration.createEntityManagerFactory() is doing 'under the covers' so to speak and a propritary interface could
be offered that could obtain the ejb3COnfiguration from a given EntityManagerFactory.
Opinions on this please?
-Thom
|