org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress

Spring JIRA | Purnendu Das | 9 years ago
  1. 0

    The System is returning with The following exception stack trace Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:289) at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:97) at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:212) at org.springframework.orm.jpa.JpaAccessor.translateIfNecessary(JpaAccessor.java:152) at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:190) at org.springframework.orm.jpa.JpaTemplate.flush(JpaTemplate.java:281) at javaapplication5.TripDaoimp.save(TripDaoimp.java:40) at javaapplication5.TestService.save(TestService.java:35) at javaapplication5.Test.setTrip(Test.java:32) at javaapplication5.Main.main(Main.java:25) Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:294) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:346) at $Proxy17.flush(Unknown Source) at org.springframework.orm.jpa.JpaTemplate$8.doInJpa(JpaTemplate.java:283) at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:185) ... 5 more The classes are as below /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication5; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; /** * * @author Purnendu */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); Test test = (Test) ctx.getBean("Test"); test.setTrip(20); } } package javaapplication5; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; /** * * @author Purnendu */ public class Test { static String text = "fhgvjhvhuj"; String text1; private TestService testService; public Test() { text1 = "the initiated one"; } String getTrip(Integer Id) { Trip trip = getTestService().findById(100); return trip.getDepcity(); } void setTrip( Integer Id) { Trip t = new Trip(968); t.setPersonid(new Person(1)); getTestService().save(t); } public TestService getTestService() { return testService; } public void setTestService(TestService testService) { this.testService = testService; } } /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication5; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; /** * * @author Purnendu */ public class TestService { private TripDaoimp tripDaoimp; public TripDaoimp getTripDaoimp() { return tripDaoimp; } public void setTripDaoimp(TripDaoimp tripDaoimp) { this.tripDaoimp = tripDaoimp; } Trip findById(int i) { return getTripDaoimp().findById(i); } void save( Trip t) { getTripDaoimp().save(t); } } /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication5; import java.util.List; import org.springframework.orm.jpa.support.JpaDaoSupport; import org.springframework.transaction.annotation.Transactional; /** * * @author Purnendu */ public class TripDaoimp extends JpaDaoSupport implements TripDao { public Trip findById(Integer id) { return getJpaTemplate().find(Trip.class, id); } public List<Trip> findByName(String name) { throw new UnsupportedOperationException("Not supported yet."); } public List<Trip> findByStreetName(String streetName) { throw new UnsupportedOperationException("Not supported yet."); } public List<Trip> findByEntreeNameLike(String entreeName) { throw new UnsupportedOperationException("Not supported yet."); } public List<Trip> findTripsWithVegetarianEntrees() { throw new UnsupportedOperationException("Not supported yet."); } public void save(Trip trip) { getJpaTemplate().persist(trip); getJpaTemplate().flush(); } public Trip update(Trip Trip) { throw new UnsupportedOperationException("Not supported yet."); } public void delete(Trip Trip) { throw new UnsupportedOperationException("Not supported yet."); } } <?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans file:///C:/Development/Library/spring-framework-2.5-with-dependencies/spring-framework-2.5/dist/resources/spring-beans-2.5.xsd http://www.springframework.org/schema/jee file:///C:/Development/Library/spring-framework-2.5-with-dependencies/spring-framework-2.5/dist/resources/spring-jee-2.5.xsd http://www.springframework.org/schema/tx file:///C:/Development/Library/spring-framework-2.5-with-dependencies/spring-framework-2.5/dist/resources/spring-tx-2.5.xsd "> <bean id='Test' class='javaapplication5.Test'> <property name="testService" ref="TestService"/> </bean> <bean id='TestService' class='javaapplication5.TestService'> <property name="tripDaoimp" ref="tripDaoimp"/> </bean> <bean id='tripDaoimp' class="javaapplication5.TripDaoimp"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="generateDdl" value="false" /> <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" /> </bean> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/hotel"/> <property name="username" value="root"/> <property name="password" value="admin123"/> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> <property name="dataSource" ref="dataSource"/> </bean> </beans> <?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="JavaApplication5PU" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>javaapplication5.Person</class> <class>javaapplication5.Trip</class> <properties> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.password" value="admin123"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/hotel"/> <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/> </properties> </persistence-unit> </persistence>

    Spring JIRA | 9 years ago | Purnendu Das
    org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
  2. 0

    The System is returning with The following exception stack trace Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:289) at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:97) at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:212) at org.springframework.orm.jpa.JpaAccessor.translateIfNecessary(JpaAccessor.java:152) at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:190) at org.springframework.orm.jpa.JpaTemplate.flush(JpaTemplate.java:281) at javaapplication5.TripDaoimp.save(TripDaoimp.java:40) at javaapplication5.TestService.save(TestService.java:35) at javaapplication5.Test.setTrip(Test.java:32) at javaapplication5.Main.main(Main.java:25) Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:294) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:346) at $Proxy17.flush(Unknown Source) at org.springframework.orm.jpa.JpaTemplate$8.doInJpa(JpaTemplate.java:283) at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:185) ... 5 more The classes are as below /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication5; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; /** * * @author Purnendu */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); Test test = (Test) ctx.getBean("Test"); test.setTrip(20); } } package javaapplication5; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; /** * * @author Purnendu */ public class Test { static String text = "fhgvjhvhuj"; String text1; private TestService testService; public Test() { text1 = "the initiated one"; } String getTrip(Integer Id) { Trip trip = getTestService().findById(100); return trip.getDepcity(); } void setTrip( Integer Id) { Trip t = new Trip(968); t.setPersonid(new Person(1)); getTestService().save(t); } public TestService getTestService() { return testService; } public void setTestService(TestService testService) { this.testService = testService; } } /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication5; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; /** * * @author Purnendu */ public class TestService { private TripDaoimp tripDaoimp; public TripDaoimp getTripDaoimp() { return tripDaoimp; } public void setTripDaoimp(TripDaoimp tripDaoimp) { this.tripDaoimp = tripDaoimp; } Trip findById(int i) { return getTripDaoimp().findById(i); } void save( Trip t) { getTripDaoimp().save(t); } } /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication5; import java.util.List; import org.springframework.orm.jpa.support.JpaDaoSupport; import org.springframework.transaction.annotation.Transactional; /** * * @author Purnendu */ public class TripDaoimp extends JpaDaoSupport implements TripDao { public Trip findById(Integer id) { return getJpaTemplate().find(Trip.class, id); } public List<Trip> findByName(String name) { throw new UnsupportedOperationException("Not supported yet."); } public List<Trip> findByStreetName(String streetName) { throw new UnsupportedOperationException("Not supported yet."); } public List<Trip> findByEntreeNameLike(String entreeName) { throw new UnsupportedOperationException("Not supported yet."); } public List<Trip> findTripsWithVegetarianEntrees() { throw new UnsupportedOperationException("Not supported yet."); } public void save(Trip trip) { getJpaTemplate().persist(trip); getJpaTemplate().flush(); } public Trip update(Trip Trip) { throw new UnsupportedOperationException("Not supported yet."); } public void delete(Trip Trip) { throw new UnsupportedOperationException("Not supported yet."); } } <?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans file:///C:/Development/Library/spring-framework-2.5-with-dependencies/spring-framework-2.5/dist/resources/spring-beans-2.5.xsd http://www.springframework.org/schema/jee file:///C:/Development/Library/spring-framework-2.5-with-dependencies/spring-framework-2.5/dist/resources/spring-jee-2.5.xsd http://www.springframework.org/schema/tx file:///C:/Development/Library/spring-framework-2.5-with-dependencies/spring-framework-2.5/dist/resources/spring-tx-2.5.xsd "> <bean id='Test' class='javaapplication5.Test'> <property name="testService" ref="TestService"/> </bean> <bean id='TestService' class='javaapplication5.TestService'> <property name="tripDaoimp" ref="tripDaoimp"/> </bean> <bean id='tripDaoimp' class="javaapplication5.TripDaoimp"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="generateDdl" value="false" /> <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" /> </bean> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/hotel"/> <property name="username" value="root"/> <property name="password" value="admin123"/> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> <property name="dataSource" ref="dataSource"/> </bean> </beans> <?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="JavaApplication5PU" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>javaapplication5.Person</class> <class>javaapplication5.Trip</class> <properties> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.password" value="admin123"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/hotel"/> <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/> </properties> </persistence-unit> </persistence>

    Spring JIRA | 9 years ago | Purnendu Das
    org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
  3. 0

    Static Asset blobs cannot be saved to the database

    GitHub | 3 years ago | phillipuniverse
    javax.persistence.TransactionRequiredException: no transaction is in progress
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Cannot get @Transactional to work properly in Spring 3

    Stack Overflow | 5 years ago | Arash Sharif
    javax.persistence.TransactionRequiredException: no transaction is in progress
  6. 0

    Getting Exceptions while persisting data

    Stack Overflow | 4 years ago | Apurv Kulkarni
    javax.persistence.TransactionRequiredException: no transaction is in progress

    4 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. javax.persistence.TransactionRequiredException

      no transaction is in progress

      at org.hibernate.ejb.AbstractEntityManagerImpl.flush()
    2. Hibernate EJB
      AbstractEntityManagerImpl.flush
      1. org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:294)
      1 frame
    3. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:597)
      4 frames
    4. Spring ORM
      ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke
      1. org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:346)
      1 frame
    5. Unknown
      $Proxy17.flush
      1. $Proxy17.flush(Unknown Source)
      1 frame
    6. Spring ORM
      JpaTemplate.flush
      1. org.springframework.orm.jpa.JpaTemplate$8.doInJpa(JpaTemplate.java:283)
      2. org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:185)
      3. org.springframework.orm.jpa.JpaTemplate.flush(JpaTemplate.java:281)
      3 frames
    7. javaapplication5
      Main.main
      1. javaapplication5.TripDaoimp.save(TripDaoimp.java:40)
      2. javaapplication5.TestService.save(TestService.java:35)
      3. javaapplication5.Test.setTrip(Test.java:32)
      4. javaapplication5.Main.main(Main.java:25)
      4 frames