Announcement Announcement Module
Collapse
No announcement yet.
JPA +JTA + Glassfish + problem with storing any data Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JPA +JTA + Glassfish + problem with storing any data

    Since a few days I am trying to persist anything in MySQL, but without success. I configured data source as well as connection pool in Glassfish.
    Here is my method that I use to persist User object:
    Code:
        @Override
        @Transactional
        public void insertUser(User user) {
            entityManager.persist(user);
           // entityManager.flush();
        }
    Without flush there is no error, but database stays empty. With flush I have this error:
    "javax.persistence.TransactionRequiredExceptio n: no transaction is in progress"

    However, I am able to read from database when I store data manualy with such method:
    Code:
          @Override
        public List<User> findAllUsers() {
            CriteriaBuilder builder = entityManager.getCriteriaBuilder();
            CriteriaQuery<User> cq = builder.createQuery(User.class);
            Root<User> root = cq.from(User.class);
            cq.select(root);
            return entityManager.createQuery(cq).getResultList();
        }
    Concerning this I think that my Glassfish configuration is ok and database connection works fine.
    Here is my root-context.xml. I tried a lot of different things that I have found, but nothing helps. I am new to Spring and I will appreciate your help because I have no ideas left after one week of trying .
    Code:
      
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
        xmlns:p="http://www.springframework.org/schema/p"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
                            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
                            http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
                            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
                            http://www.springframework.org/schema/data/jpa
                            http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">    
        <!-- Root Context: defines shared resources visible to all other web components -->
            
        <context:spring-configured />
        <context:annotation-config />
        <context:component-scan base-package="com.myPackage" />
       
          <bean id="persistenceExceptionTranslationPostProcessor"
          class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
        
        <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="jdbc/telcoData" />
        </bean>
    
        <bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
          <property name="dataSource" ref="dataSource" />
          <property name="jtaDataSource" ref="dataSource" />
          <property name="packagesToScan" value="com.myPackage.persistence.model" />
          <property name="jpaVendorAdapter">
             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
          </property>
          <property name="jpaPropertyMap">
                <map>
                <entry key="hibernate.connection.release_mode" value="after_statement"/>
                <entry key="hibernate.current_session_context_class" value="jta"/>
                <entry key="javax.persistence.transactionType" value="jta"/>
                </map>
          </property>      
          <property name="jpaProperties">
             <props>
                <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.SunOneJtaPlatform</prop>
             </props>
          </property>
       </bean>
       
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    
        <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
        <tx:jta-transaction-manager/>
        <tx:annotation-driven />
        <mvc:annotation-driven />
        <mvc:resources mapping="/resources/**" location="/resources/" />
    </beans>

  • #2
    I enabled dobug logs. Maybe that could help somehow. I have no idea what else could I try.
    Code:
    2014-05-19T10:31:49.968+0200|INFO: DEBUG: org.hibernate.jpa.spi.AbstractEntityManagerImpl - Looking for a JTA transaction to join
    2014-05-19T10:31:49.968+0200|INFO: DEBUG: org.hibernate.jpa.spi.AbstractEntityManagerImpl - Unable to join JTA transaction
    2014-05-19T10:31:49.968+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.968+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.968+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.968+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.968+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.969+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.969+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.969+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.969+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.969+0200|INFO: DEBUG: org.springframework.orm.jpa.EntityManagerFactoryUtils - Closing JPA EntityManager
    2014-05-19T10:31:49.969+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.969+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.969+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.969+0200|INFO: DEBUG: org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
    2014-05-19T10:31:49.970+0200|INFO: DEBUG: org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [public java.lang.String com.project.controller.PersonController.test(java.util.Locale,org.springframework.ui.Model)]: javax.persistence.TransactionRequiredException: no transaction is in progress
    2014-05-19T10:31:49.974+0200|INFO: DEBUG: org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolving exception from handler [public java.lang.String com.project.controller.PersonController.test(java.util.Locale,org.springframework.ui.Model)]: javax.persistence.TransactionRequiredException: no transaction is in progress
    2014-05-19T10:31:49.974+0200|INFO: DEBUG: org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [public java.lang.String com.project.controller.PersonController.test(java.util.Locale,org.springframework.ui.Model)]: javax.persistence.TransactionRequiredException: no transaction is in progress
    2014-05-19T10:31:49.976+0200|INFO: DEBUG: org.springframework.web.servlet.DispatcherServlet - Could not complete request
    javax.persistence.TransactionRequiredException: no transaction is in progress
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.checkTransactionNeeded(AbstractEntityManagerImpl.java:1171)
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1332)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:366)
        at com.sun.proxy.$Proxy339.flush(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241)
        at com.sun.proxy.$Proxy339.flush(Unknown Source)
        at com.project.persistence.dao.impl.UserDAOImpl.insertUser(UserDAOImpl.java:32)
        at com.project.persistence.user.impl.UserManagerImpl.insertUser(UserManagerImpl.java:22)
        at com.project.controller.PersonController.test(PersonController.java:113)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
        at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
        at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
        at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
        at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
        at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
        at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
        at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
        at java.lang.Thread.run(Thread.java:744)

    Comment


    • #3
      I have still the same problem even after I resigned from JTA and Glassfish managed datasource and configured Spring managed transaction manager and entity manager factory. Database is deployed and tables are created, but I cannot persist any data. Always the same error. I even changed PC to different one and started from the scratch without success. I try some example and in the end problem is the same. It is about second week since I have this problem and I am really desperate. Maybe someone could recommend me some example project that works and combines even only JPA and MySQL.

      Comment


      • #4
        This is a tad old but is a good tutorial that looks to have MySQL example in it. If you look @ his application.properties file he has MySQL settings commented out.
        This tutorial describes how you can implement the repository layer of your application by using Spring Data JPA.

        Comment

        Working...
        X