Announcement Announcement Module
Collapse
No announcement yet.
PersistenceContext closed in Websphere CMT Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PersistenceContext closed in Websphere CMT

    Our application use IBM WAS6.1 container with EJB3.0 feature pack. Transactions are container managed via EJB3.0 transactions (not spring transactions) started from ejb service bean. We use Spring for DI.

    Approach is EJB3.0 Bean Service, Spring ServiceImpl and Spring DAO on DB2 db.

    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:

    Code:
        [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:

    Code:
     <?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>
    </persistence>
    Spring Context:

    Code:
     <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:

    Code:
     public class DbsJpaDaoImpl implements IDbsJpaDao{
    
    	@PersistenceContext
    	private EntityManager entityManager;
    
    	public List<DbsLimit> subscriberLimitInquiry(){
            ...
            return entityManager.createQuery(queryString);
            }
    EJB3.0 Service Bean:

    Code:
    @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:


    Code:
       <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.

    Code:
     <bean id="transactionManager"
    	class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>
    Any opinions?

    Thanks.

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

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