I\'m trying to get started with using Guice Persist and JPA, which recommends using configuration via persistence.xml. Coming from a native Hibernate background where confi
Assuming that you have a PersistenceProvider
implementation (e.g. Hibernate), you can use the PersistenceProvider#createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) method to bootstrap an EntityManagerFactory
without needing a persistence.xml
.
However, it's annoying that you have to implement the PersistenceUnitInfo
interface, so you are better off using Spring or Hibernate which both support bootstrapping JPA without a persistence.xml
file:
this.nativeEntityManagerFactory = provider.createContainerEntityManagerFactory(
this.persistenceUnitInfo,
getJpaPropertyMap()
);
Where the PersistenceUnitInfo is implemented by the Spring-specific MutablePersistenceUnitInfo class.
Check out this article for a nice demonstration of how you can achieve this goal with Hibernate.