Transaction is not committed when using local/global JNDI datasource lookup in a spring/eclipselink project in weblogic

StackOverflow https://stackoverflow.com/questions/22863491

Question

When I use the global JNDI name in the persistence.xml, everything works ok.

It goes wrong when I use a local JNDI name, add the resource-ref to the web.xml and map the local name to the global name in the weblogic.xml. He deploys successfully, finds the datasource, does selects and inserts, but never commits! The commit does happen when I use the global JNDI name directly in the persistence.xml.

My spring context is as follows:

<bean id="localContainerEntityManagerFactoryBean" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="rctUnit" />
</bean>

<bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager" />

<tx:annotation-driven transaction-manager="transactionManager" />

The persistence.xml after the change:

<persistence-unit name="rctUnit" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:comp/env/jdbc/rct</jta-data-source>

And the following added to the web.xml and the weblogic.xml:

<resource-ref>
    <description>RCT DB</description>
    <res-ref-name>jdbc/rct</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

<resource-description>
    <res-ref-name>jdbc/rct</res-ref-name>
    <jndi-name>db.datasource.rct</jndi-name>
</resource-description>

Following versions are used:

  • eclipselink: 2.0.2
  • jpa: 1.0.0
  • spring: 3.2.0.RELEASE
  • weblogic: 10.3.3
Was it helpful?

Solution

I was able to solve it by adding an eclipseLink property to the persistence.xml:

<property name="eclipselink.target-server" value="weblogic" />

I don't have any clue why this property is not needed when the global JNDI name is used in the persistence.xml. The eclipse property is not needed then to make it work. When using the local JNDI name in the persistence.xml, this property is needed to make the transaction commits.

OTHER TIPS

Probably because the prefix java:comp/ is different according to deployment environment, some may not use the "comp" part

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top