Announcement Announcement Module
Collapse
No announcement yet.
PersistenceContext/EntityManager not binded Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PersistenceContext/EntityManager not binded

    following the reference, I'm still in stuck on Spring+OpenJPA+Tomcat6 integeration. would you help me out, thank you.


    I do as follows, but it dose not work:
    1. versions: spring-2.5.6SEC01, OpenJPA-1.2.1, Tomcat-6.0.16
    2. copy spring-tomcat-weaver.jar to ${Tomcat}\lib;
    3. delpoy my webapp: add Context instruction to ${Tomcat}\conf\server.xml:
    Code:
        <Context docBase="myapp.war" path="/myapp">
    	<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" />
        </Context>
    4. myapp's spring bean definition file:
    Code:
          <context:annotation-config />
    
          <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
            <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
            <property name="url" value="jdbc\:hsqldb\:${user.home}/ar/internalds" />
            <property name="username" value="sa" />
            <property name="password" value="" />
        </bean>
    
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
            <property name="dataSource" ref="dataSource"/>
            <property name="loadTimeWeaver">
            	<bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver" />
            </property>
        </bean>
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory"/>
        </bean>
        <tx:annotation-driven transaction-manager="transactionManager"/>
         
         <bean id="sampleDao" class="pkg.SampleDAO" />
    5. classpath: META-INF/persistence.xml
    Code:
         <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
            <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
            <properties>
            	<property name="openjpa.jdbc.DBDictionary" value="hsql(SimulateLocking=true)"/>
            </properties> 
        </persistence-unit>
    6. the DAO class:
    Code:
       public class SampleDAO {
            @PersistenceContext
    	private EntityManager em;
            
            public doSth() {
                assert(this.em != null);
          
            }
       }
    The probleam is, the EntityManager em is always Null
    Last edited by ronnin; Jul 17th, 2009, 03:45 AM. Reason: correct
Working...
X