Search code examples
jpamaven-2persistence.xml

Can I have two persistence.xml files in my spring maven project


Is it possible for me to have two different persistence.xml files under META-INF eg. persistence-one.xml and persistence-two.xml and then somehow use <property name="persistenceXmlLocation" value="${db.persistence.file.name}"/> in my spring-context.xml to use the appropriate one using property files ?

I am doing this because I have two separate environments with different configurations - providers/dialects etc.

If I do above changes then I get Caused by: java.io.FileNotFoundException: and it's not able to read the appropriate file.

How I can make this work ?

Spring 3, Hibernate 5.3


Solution

  • Whoaa... spring 3 with hibernate 5 is going to be... challenging.

    In any case, I'd try using <property name="persistenceProvider" value="org.hibernate.jpa.HibernatePersistenceProvider" /> instead of jpaVendorAdapter.

    You might want to take a look at the bean's javadoc to see which other properties might be relevant (alternatively, you can use the persistenceXmlLocation property and load all the properties from either persistence_dev.xml or persistence_prod.xml)