views:

33

answers:

1

The Spring configuration I am using contains the definition of a persistenceUnitPostProcessor within my entityManagerFactory bean.

When I run a JUnit test (i.e. outside of the container) the post processor is being invoked, yet when it participates as part of a deployed web app (running in Glassfish v3) the post processor is not being executed. Everything else works, the spring context is loaded correctly, all the defined beans load, it's just that the post processor is never fired.

The purpose of the entity scanner is to locate @Entity annotated classes. The project is split between two modules, one which contains Domain Models and the other which contains DAOs and persistence code.

The scanner code is loosely based on the blog post here : auto-scanning-jpa-entities which searches the classpath. As I say, this all works fine outside of the container.

The relevant spring config elements showing the post processor bean (trimmed for brevity) are as follows:

<bean id="entityScanner" class="com.inno.spring.EntityScanner"> 
    <property name="classPathFilter">
        <value>insurer</value>
    </property>
    <property name="targetPersistenceUnits"> 
        <value>unitTest-hsqldb</value> 
    </property> 
    <property name="classesToExclude"> 
        <value></value> 
    </property> 
</bean>

with the entity manager factory being defined as follows:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="loadTimeWeaver">
        <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
    </property>
    <property name="dataSource">
        <!-- Workaround to allow custom isolation levels -->
        <bean class="org.springframework.jdbc.datasource.lookup.IsolationLevelDataSourceRouter">
            <property name="defaultTargetDataSource" ref="unitTestDataSource" />
            <property name="targetDataSources">
                <map>
                    <entry key="ISOLATION_READ_UNCOMMITTED">
                        <bean
                            class="org.springframework.jdbc.datasource.IsolationLevelDataSourceAdapter">
                            <property name="targetDataSource" ref="unitTestDataSource" />
                            <property name="isolationLevelName" value="ISOLATION_READ_UNCOMMITTED" />
                        </bean>
                    </entry>
                </map>
            </property>
        </bean>
    </property>
    <property name="persistenceUnitName" value="unitTest-hsqldb" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database" value="HSQL" />
            <property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect" />
            <property name="showSql" value="${jpa.hibernate.showSql}" />
            <property name="generateDdl" value="${jpa.hibernate.generateDdl}" />
        </bean>
    </property>
    <property name="jpaPropertyMap">
        <map>
            <entry key="hibernate.ejb.interceptor" value="com.inno.jpa.interceptors.InsurerInterceptor" />
        </map>
    </property>
    <property name="persistenceUnitPostProcessors"> 
        <list> 
            <ref bean="entityScanner" /> 
        </list> 
    </property> 

</bean>

I am a relative newbie to Spring and JPA so go easy on me if I've made an obvious mistake!

Thanks Steve

A: 

I gave up trying to get this to work in the end, instead I moved the code into the same project. Seems a bit silly to me that the jar-file option under the persistence unit definition in persistence.xml isn't a little more flexible in terms of being able to scan the classpath directly.

deevodavis