Skip to content

Dealing with multiple persistence units - Documentation Corrections [SPR-6781] #11447

@spring-projects-issues

Description

@spring-projects-issues

Rob Winch opened SPR-6781 and commented

I have a few corrections for the "Dealing with multiple persistence units" example provided in the spring documentation (http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/orm.html#orm-jpa-multiple-pu).

First, the bean of type DefaultPersistenceUnitManager should change the property name persistenceXmlLocation to persistenceXmlLocations to avoid the error below.

Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [java.lang.String] for property 'persistenceXmlLocation': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:289)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:154)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:452)
... 40 more

Second, LocalContainerEntityManagerFactoryBean should specify the property persistenceUnitName to avoid the following exception from being thrown:

Caused by: java.lang.IllegalStateException: No single default persistence unit defined in {org/springframework/orm/jpa/domain/persistence-multi.xml, classpath:/my/package/**/custom-persistence.xml, classpath*:META-INF/persistence.xml}
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.obtainDefaultPersistenceUnitInfo(DefaultPersistenceUnitManager.java:367)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.determinePersistenceUnitInfo(LocalContainerEntityManagerFactoryBean.java:247)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:196)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
... 37 more

Last, the second correction leads me to ask how do I appropriately deal with the other persistence unit names? Do I have to create a new instance of LocalContainerEntityManagerFactoryBean for each persistence unit (hope not)?


Affects: 2.5.6, 3.0 GA

Referenced from: commits 2d6ea2f

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions