Hi,
I'm using Spring 3.1.3 Release and Hibernate 4.
I have multiple maven module in my project. In each module, i defined some domain Object.
In module-core, i defined my persistence.xml that have onlyCode:-- module-core -- module-sending (depends on module-core) -- module-web (depends on module-core)
and in persistence context file:Code:<persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL">
In fact, the property "packagesToScan" will do not work. I've looked in the class DefaultPersistenceUnitManager.readPersistenceUnitI nfos() and i foundCode:... <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" > <property name="jpaVendorAdapter" ref="jpaAdapter" /> <property name="persistenceUnitName" value="testPU"/> <property name="dataSource" ref="dataSource"/> <property name="packagesToScan"> <list> <value>com.test.core.domain</value> <value>com.test.web.domain</value> <value>com.test.sending.domain</value> </list> </property> </bean> ...
So if i have my persistence.xml defined with name="testPU" and then in LocalContainerEntityManagerFactoryBean, i defined persistenceUnitName="testPU", the method buildDefaultPersistenceUnitInfo with never be called. So no packages that i set before will be scan.Code:boolean buildDefaultUnit = (this.packagesToScan != null || this.mappingResources != null); PersistenceUnitReader reader = new PersistenceUnitReader(this.resourcePatternResolver, this.dataSourceLookup); SpringPersistenceUnitInfo[] readInfos = reader.readPersistenceUnitInfos(this.persistenceXmlLocations); for (SpringPersistenceUnitInfo readInfo : readInfos) { infos.add(readInfo); if (this.defaultPersistenceUnitName != null && this.defaultPersistenceUnitName.equals(readInfo.getPersistenceUnitName())) { buildDefaultUnit = false; } } if (buildDefaultUnit) { infos.add(buildDefaultPersistenceUnitInfo());//--> this method will scan package defined in context }
Could you see for me what is wrong? And WHY this
EDIT: when i remove my persistence.xml file, it works like a charm.if (this.defaultPersistenceUnitName != null &&
this.defaultPersistenceUnitName.equals(readInfo.ge tPersistenceUnitName())) {
buildDefaultUnit = false;
}
Regards


Reply With Quote
