Question

In the online source code generation tool SpringFuse the suggest when using Spring not to name the persistence unit persistence.xml. Rather they rename the file to spring-persistence.xml: https://github.com/jaxio/generated-projects/blob/master/jpa2-backend/src/main/resources/META-INF/spring-persistence.xml . They say:

It is named spring-persistence.xml to prevent JBoss from picking it automatically, which would create a mess as we use Spring.

But why would this create a mess and what type of mess? We use spring and have the file named persistence.xml and it works. We use JBoss AS 6.1.

Was it helpful?

Solution

You might end up with two copies of the same persistence context (EntityManagerFactory), one bootstrapped by JBoss and one by the Spring app context. Also as I recall, JBoss is quite strict with persistence.xml validation so you might end up with validation issues (e.g. explicitly listing entity classes vs classpath scanning). And if you do run into issues, disabling JBoss scanning is easier said than done.

Anyways, do note that if you are using a recent-enough version of Spring (3.1.x+?), you don't need a persistence.xml at all. See http://docs.spring.io/spring/docs/3.2.6.RELEASE/javadoc-api/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.html#setPackagesToScan(java.lang.String...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top