I have a maven-built CDI-based Java SE app, which has a core module, and other modules.
Core has the persistence.xml
and some entities.
Modules have additional entities.
How can I add the entities to the spotlight of the persistence unit?
I have read Hibernate manual, http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/configuration.html#setup-configuration-packaging
I have also seen these SO questions
- How can I merge / extend persistence units from different JARs?
- define jpa entity classes outside of persistence.xml
- Programmatically loading Entity classes with JPA 2.0?
I am looking for a solution where Hibernate would scan for all loaded classes, or, would pick up some config file form the other jars (like e.g. CDI does with beans.xml
).
My app does not use Spring. I don't insist on portability - I'll stick with Hibernate.
- Is there some such solution?
- Is there's a way to create a PU from
persistence.xml
and add classes to it programmatically? - Can I add @Entity classes to
EntityManagerFactory
after it was created?
Update: I found in org.hibernate.ejb.Ejb3Configuration
:
public Ejb3Configuration configure(String persistenceUnitName, Map integration)