Results 1 to 2 of 2

Thread: packagesToScan in LocalContainerEntityManagerFactoryBea doesn't work if ...

  1. #1
    Join Date
    Jan 2013
    Posts
    1

    Default 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 at 04:48 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    The packagesToScan attribute is there for xml less configuration ie. no persistence.xml... When using a persistence xml it follows the JPA spec.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •