persistenceUnitName with JPA2.1

时间:2014-09-04 02:16:50

标签: spring persistence.xml jpa-2.1 hibernate-entitymanager spring-orm

我正在使用Spring项目(使用JPA2.1),并且persistenceUnitName在该项目中被定义为“default”。

我已经在另一个Spring批处理项目中定义了这个项目的依赖项(使用maven)(在另一个项目中使用spring-core.jar来重用一些实体类和其他东西)(也就是使用spring-JPA2.1) 。

当我在这个项目中定义相同的persistenceUnitName时,它会给我一个persistenceUnitName的冲突错误。

<bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
          p:persistenceUnitName="default"
          p:jpaVendorAdapter-ref="jpaVendorAdapter"
          p:dataSource-ref="dataSource" />

但是当我在这个项目中更改了persistenceUnitName的名称时,它无法创建导入项目的persistenceUnitName(“default”)。因此无法创建导入项目的JPA类(我在其中定义了pom.xml中的依赖项)

Error creating bean with name 'SampleJpa': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'default' is defined

请建议我一些解决方案。实际上这是以hibernate的方式工作,但迁移给我们带来了困难。

1 个答案:

答案 0 :(得分:0)

我在导入的项目中创建了一个新模块,并从中分离了persistence.xml。然后我导入了模块(模块现在只有我需要在另一个项目中导入的类而不是整个核心)。这样它工作正常。