Question

I am getting confused about the way to configure spring's JTA JNDI with weblogic:

as I understood, <jee:jndi-lookup id="entityManagerFactory" jndi-name="jdbc/oracledb" />

serves to bind the datasource with the name (already created in the weblogic server) in an EntityManagerFactory. and then to allow spring detecte the JPA annotations and injects the appropriate values in the DAO we define the bean

<bean       
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

and for the jndi:

    <jee:jndi-lookup id="entityManagerFactory" jndi-name="jdbc/oracledb" />

to activate spring's jta:

    <tx:jta-transaction-manager />

my persistence.xml file is:

   <persistence-unit name="ebankingUnit"
    transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/oracledb</jta-data-source>
    <class>com.datamodel.Product</class>

the error I'm getting is that the entity Manager is NULL inside the DAO,

Is there any problem with my configuration?

Was it helpful?

Solution

The lookup <jee:jndi-lookup id="entityManagerFactory" jndi-name="jdbc/oracledb" /> is almost certainly for the DataSource, not the entityManagerFactory. Your configuration would probably need to be

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/oracledb" />

<bean
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        id="entityManagerFactory">
        <property name="dataSource" ref="dataSource" />
         <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
    </bean>

<tx:jta-transaction-manager />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top