Announcement Announcement Module
Collapse
No announcement yet.
Spring Data JPA, MVC WebSphere 6.1.0.39 WebSphereUowTransactionManager - transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data JPA, MVC WebSphere 6.1.0.39 WebSphereUowTransactionManager - transaction

    Hi All,

    I have Spring MVC application build using Spring data JPA for database access and deployed in the Websphere 6.1.0.39. I want to use the TransactionManager to control the transactions and using the container specific one WebSphereUowTransactionManager. I had the same application working fine with Hibernate session factory and since when I migrated it use Spring Data Jpa we are getting bizarre error, complaining about transaction not being active. Followings are some config, code and error log.

    Application context declaring entityManagerFactory
    Code:
    <bean id="jpaEntityManagerFactory" name="entityManagerFactory"
              class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="packagesToScan" value="com.mycompany.domain.model"/>
            <property name="jpaDialect">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
            </property>
    
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="showSql" value="${hibernate.show_sql}"/>
                    <property name="databasePlatform" value="${hibernate.dialect}"/>
                </bean>
            </property>
            <property name="jpaProperties">
                <props>
                    <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</prop>
                    <!-- prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop -->
                </props>
            </property>
        </bean>
    
        <jpa:repositories base-package="com.mycompany.domain.repository"/>
    
    
     <bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>
    
     <tx:annotation-driven transaction-manager="transactionManager"/>

    Filter entry in web.xml
    Code:
     <!--- JPA Open Session In View filter to allow objects to be lazy-loaded during page rendering -->
        <filter>
            <filter-name>jpaFilter</filter-name>
            <filter-class>
                org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
            </filter-class>
            <init-param>
                <param-name>entityManagerFactoryBeanName</param-name>
                <param-value>entityManagerFactory</param-value>
            </init-param>
            <init-param>
                <param-name>flushMode</param-name>
                <param-value>MANUAL</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>jpaFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    Following is the code for controller
    Code:
    Controller
    @RequestMapping(value = "/admin/product-type")
    public class ProductTypeAddAttributeController {
    
        @Autowired
        private AddRemoveAttributeService addRemoveAttributeService;
    
        @Autowired
        private AttributeLifeCycleManager attributeLifeCycleManager;
    
        @RequestMapping(value = "{productTypeId}/add-attribute", method = RequestMethod.POST)
        @ResponseBody
        public String addAttributeToProductType(@PathVariable("productTypeId") ProductType productType,
                @RequestParam("attributeId") String attributeId, @RequestParam("associationLevel") String associationLevelName)
                throws ProductTypeNotUpdatedException {
    
            LOGGER.debug("Attribute ID is {}", attributeId);
            LOGGER.debug("Selected product type's id is {}", productType.getId());
            LOGGER.debug("Association level is {}", associationLevelName);
    
            Attribute attributeToBeAssociated = attributeLifeCycleManager.findById(Long.parseLong(attributeId));
    
            AttributeAssociationLevelType associationLevel = obtainAssociationLevel(associationLevelName);
    
            addRemoveAttributeService.addAttributeToProductType(attributeToBeAssociated, productType, associationLevel);
            return SUCCESS_MESSAGE;
        }
    
        
    private AttributeAssociationLevelType obtainAssociationLevel(String associationLevelName) {
    
            if (ASSOCIATED_WITH_PRODUCT.equals(associationLevelName)) {
                return PRODUCT;
            }
            return SKU;
    
        }
    
    
    
    }
    Code for AddRemoveAttributeService service used by Controller


    Code:
    @Service("attributeService")
    @Transactional
    public class DefaultAddRemoveAttributeService implements AddRemoveAttributeService {
    
     @Autowired
        private AttributeRepository attributeRepository;
    
        @Autowired
        private ProductTypeRepository productTypeRepository;
    
      public void addAttributeToProductType(Attribute attributeToBeAssociated, ProductType productType,
                AttributeAssociationLevelType associationLevel) {
    
            if (productType.getProductAttributes().contains(attributeToBeAssociated)
                    || productType.getSkuAttributes().contains(attributeToBeAssociated)) {
                /*
                 * Attribute already associated. Do not add again
                 */
                LOGGER.error("Attribute already associated to product type");
                throw new ProductTypeNotUpdatedException("Attribute already associated to product type");
    
            } else {
                if (associationLevel == AttributeAssociationLevelType.PRODUCT) {
                    productType.addProductAttribute(attributeToBeAssociated);
    
                } else if (associationLevel == AttributeAssociationLevelType.SKU) {
                    productType.addSkuAttribute(attributeToBeAssociated);
    
                }
    
                if (productTypeRepository.save(productType) == null) {
    
                    LOGGER.error("Error updating product type.");
                    throw new ProductTypeNotUpdatedException("Error updating product type.");
                }
            }
        }
    
    
    
    }

    Repository code
    Code:
    public interface ProductTypeRepository extends JpaRepository<ProductType, Long> {
    
        @Query("FROM ProductType productType where productType.parent = null")
        List<ProductType> findRootProductType();
    
        List<ProductType> findBySearchNameIgnoreCase(String searchName);
    
    }
    And here is the logs
    Code:
    [12/12/12 11:22:16:867 GMT] 00000074 XATransaction E   J2CA0030E: Method enlist caught java.lang.IllegalStateException: Transaction is inactive or prepared
    	at com.ibm.ws.Transaction.JTA.TransactionImpl.enlistResource(TransactionImpl.java:3289)
    	at com.ibm.ws.Transaction.JTA.TranManagerSet.enlist(TranManagerSet.java:407)
    	at com.ibm.ejs.j2c.XATransactionWrapper.enlist(XATransactionWrapper.java:699)
    	at com.ibm.ejs.j2c.ConnectionEventListener.localTransactionStarted(ConnectionEventListener.java:757)
    	at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.processLocalTransactionStartedEvent(WSRdbManagedConnectionImpl.java:1833)
    I'll post more logs in next one,as we have restriction to not post more than 10000 charaters.
    Could any one please take a look and provide some assistance? Thanks in advance

    Thanks & Regards,
    Irfan

  • #2
    Here are complete logs
    Code:
    [12/12/12 11:22:16:867 GMT] 00000074 XATransaction E   J2CA0030E: Method enlist caught java.lang.IllegalStateException: Transaction is inactive or prepared
    	at com.ibm.ws.Transaction.JTA.TransactionImpl.enlistResource(TransactionImpl.java:3289)
    	at com.ibm.ws.Transaction.JTA.TranManagerSet.enlist(TranManagerSet.java:407)
    	at com.ibm.ejs.j2c.XATransactionWrapper.enlist(XATransactionWrapper.java:699)
    	at com.ibm.ejs.j2c.ConnectionEventListener.localTransactionStarted(ConnectionEventListener.java:757)
    	at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.processLocalTransactionStartedEvent(WSRdbManagedConnectionImpl.java:1833)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.beginLocalTransactionIfNecessary(WSJdbcConnection.java:524)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.beginTransactionIfNecessary(WSJdbcConnection.java:708)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:2084)
    	at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:2039)
    	at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
    	at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)
    	at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
    	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2549)
    	at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2494)
    	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2821)
    	at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:113)
    	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
    	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
    	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
    	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
    	at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)
    	at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerSynchronization.afterCommit(ExtendedEntityManagerCreator.java:478)
    	at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCommit(TransactionSynchronizationUtils.java:133)
    	at org.springframework.transaction.jta.JtaAfterCompletionSynchronization.afterCompletion(JtaAfterCompletionSynchronization.java:59)
    	at com.ibm.ws.uow.ComponentContextSynchronizationWrapper.afterCompletion(ComponentContextSynchronizationWrapper.java:84)
    	at com.ibm.ws.Transaction.JTA.RegisteredSyncs.distributeAfter(RegisteredSyncs.java:424)
    	at com.ibm.ws.Transaction.JTA.TransactionImpl.distributeAfter(TransactionImpl.java:3933)
    	at com.ibm.ws.Transaction.JTA.TransactionImpl.postCompletion(TransactionImpl.java:3912)
    	at com.ibm.ws.Transaction.JTA.TransactionImpl.prepareResources(TransactionImpl.java:2229)
    	at com.ibm.ws.Transaction.JTA.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:1690)
    	at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java:1646)
    	at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java:1581)
    	at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java:247)
    	at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java:168)
    	at com.ibm.ws.uow.UOWManagerImpl.uowCommit(UOWManagerImpl.java:1059)
    	at com.ibm.ws.uow.UOWManagerImpl.uowEnd(UOWManagerImpl.java:1029)
    	at com.ibm.ws.uow.UOWManagerImpl.runUnderNewUOW(UOWManagerImpl.java:977)
    	at com.ibm.ws.uow.UOWManagerImpl.runUnderUOW(UOWManagerImpl.java:511)
    	at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:281)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:127)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:91)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy516.save(Unknown Source)
    	at com.mycompany.app.services.attribute.DefaultAddRemoveAttributeService.addAttributeToProductType(DefaultAddRemoveAttributeService.java:528)
    	at com.mycompany.app.web.controllers.admin.producttype.ProductTypeAddAttributeController.addAttributeToProductType(ProductTypeAddAttributeController.java:63)
    	at com.mycompany.app.web.controllers.admin.producttype.ProductTypeAddAttributeController$$FastClassByCGLIB$$74f0ffd4.invoke(<generated>)
    	at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
    	at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    	at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:64)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
    	at com.mycompany.app.web.controllers.admin.producttype.ProductTypeAddAttributeController$$EnhancerByCGLIB$$26e37da1.addAttributeToProductType(<generated>)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:618)
    	at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
    	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    	at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1213)
    	at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1154)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)
    	at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
    	at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
    	at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
    	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    	at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
    	at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:147)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    	at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
    	at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
    	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

    Comment

    Working...
    X