With plain JPA, 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.