1

Our application use IBM WAS6.1 container with EJB3.0 feature pack. Transactions are container managed via EJB3.0 transactions started from ejb service bean. We use Spring for DI. There are 3 layers. Spring DAO, Spring Service and EJB3.0 Bean Service.

Now i when i try to use OpenJPA with WAS6.1. EntityManager is successfully injected into SpringDAO but container closes EntityManager before transaction commits. (Datasource is JNDI datasource)

Here is the stacktrace:

[1/4/12 9:23:17:769 EET] 0000001f ExceptionUtil E   CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "inquiryReconcilation" on bean "BeanId(PaymentSystemAppV1#PaymentSystemServiceEjbV1.jar#PaymentServiceBean, null)". Exception data: <openjpa-1.0.3-SNAPSHOT-r420667:649224 fatal user error> org.apache.openjpa.persistence.InvalidStateException: You have closed the EntityManager, though the persistence context will remain active until the current transaction commits.
at org.apache.openjpa.persistence.EntityManagerImpl.assertNotCloseInvoked(EntityManagerImpl.java:1068)

Our persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="PaymentSystemEntityV1" transaction-type="JTA">
    <jta-data-source>paymentDsSrv</jta-data-source>
    <mapping-file>META-INF/namedQueries.xml</mapping-file>
    /* entities */
    <properties>
        <property name="openjpa.TransactionMode" value="managed" />
        <property name="openjpa.ConnectionFactoryMode" value="managed" />
        <property name="openjpa.jdbc.DBDictionary" value="db2" />
        <property name="openjpa.jdbc.Schema" value="PAYMENT"/>
        <property name="openjpa.Log" value="DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=TRACE"/>
    </properties>
</persistence-unit>

Spring Context:

    <bean id="dbsJpaDao" parent="daoBase" class="com.kavuntek.dds.dao.impl.DbsJpaDaoImpl" />

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

    <bean id="entityManagerFactory" class="javax.persistence.Persistence" 
         factory-method="createEntityManagerFactory" >
       <constructor-arg type="java.lang.String" value="PaymentSystemEntityV1"/>  
     </bean>

DAO:

public class DbsJpaDaoImpl implements IDbsJpaDao{

@PersistenceContext
private EntityManager entityManager;

public List<DbsLimit> subscriberLimitInquiry(){
    ...
    return entityManager.createQuery(queryString);
    }

EJB3.0 Service Bean:

@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@TransactionManagement(value = TransactionManagementType.CONTAINER)
@Interceptors(SpringBeanAutowiringInterceptor.class)
@Local(IDDSServiceV1.class)
public class DDSServiceBean iplements IDDSServiceV1{

@Autowired
private IDDSService ddsService;

public List<DbsInvoice> subscriberLimitInquiry()
... 

I tried also spring LocalContainerEntityManagerFactory with these parameters:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
       <property name="persistenceUnitName" value="PaymentSystemEntityV1"/>
       <property name="dataSource" ref="dataSource"/>
       <property name="jpaVendorAdapter">
          <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter"/>
       </property>
    </bean> 

Because transactions are not Spring managed, using WebSphereUowTransactionManager matters? Nothing changed.

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

Any opinions?

Thanks.

P.S. When i call entityManager.getTransaction() in DAO i get:

Exception data: java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead

0 Answers0