문제

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.

도움이 되었습니까?

해결책

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...)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top