I\'m trying to set up spring xml configuration without having to create a futher persistence.xml
. But I\'m constantly getting the following exception, even thou
Assuming that you have a PersistenceProvider
implementation (e.g. org.hibernate.jpa.HibernatePersistenceProvider
), 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.