Announcement Announcement Module
Collapse
No announcement yet.
packagesToScan in LocalContainerEntityManagerFactoryBea doesn't work if ... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • packagesToScan in LocalContainerEntityManagerFactoryBea doesn't work if ...

    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.
    Code:
    -- module-core
    -- module-sending (depends on module-core)
    -- module-web (depends on module-core)
    In module-core, i defined my persistence.xml that have only
    Code:
    <persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL">
    and in persistence context file:
    Code:
    ... 
        <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>
    ...
    In fact, the property "packagesToScan" will do not work. I've looked in the class DefaultPersistenceUnitManager.readPersistenceUnitI nfos() and i found
    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
    		}
    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.

    Could you see for me what is wrong? And WHY this
    if (this.defaultPersistenceUnitName != null &&
    this.defaultPersistenceUnitName.equals(readInfo.ge tPersistenceUnitName())) {
    buildDefaultUnit = false;
    }
    EDIT: when i remove my persistence.xml file, it works like a charm.

    Regards
    Last edited by khong07; Jan 14th, 2013, 05:48 AM.

  • #2
    The packagesToScan attribute is there for xml less configuration ie. no persistence.xml... When using a persistence xml it follows the JPA spec.

    Comment

    Working...
    X