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 configuration was obtained programmatically, is there a simple way to configure a JpaPersistModule without a persistence.xml file, or will a rump persistence.xml always have to exist?
If no such option exists, it might be the case where I might have to play around with PersistenceProvider (assuming the "default" parses persistence.xml somehow). Any tutorials on working with the JPA SPI?
Assuming that you have a
PersistenceProviderimplementation (e.g. Hibernate), you can use the PersistenceProvider#createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) method to bootstrap anEntityManagerFactorywithout needing apersistence.xml.However, it's annoying that you have to implement the
PersistenceUnitInfointerface, so you are better off using Spring or Hibernate which both support bootstrapping JPA without apersistence.xmlfile:Where the
PersistenceUnitInfois implemented by the Spring-specificMutablePersistenceUnitInfoclass.