Search code examples
springpersistence.xmljpa-2.1hibernate-entitymanagerspring-orm

persistenceUnitName with JPA2.1


I am having a Spring project (with JPA2.1) and persistenceUnitName is defined as "default" in that project.

I have defined the dependency (using maven) of this project (using spring-core.jar in another project to reuse some Entity classes and other stuff) in another spring batch project (that is too using spring-JPA2.1).

When I am defining the same persistenceUnitName in this project then it is giving me a conflict error of persistenceUnitName.

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

But when I changed the name of persistenceUnitName in this project then it is not able to create the persistenceUnitName ("default") of imported project. So not able to create JPA classes of imported project (for which I defined the dependency in 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

Please suggest me some solution. Actually this was working in this way with hibernate but migration is giving us hard time.


Solution

  • I created a new module in imported project and separated persistence.xml from that. And then I imported the module (module is now having only classes that I need to import in another project not the whole core). this way it is working fine.