Caused by: 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:342)
at com.sun.proxy.$Proxy64.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:262)
at com.sun.proxy.$Proxy64.flush(Unknown Source)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.flush(SimpleJpaRepository.java:397)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.saveAndFlush(SimpleJpaRepository.java:365)
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.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:333)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
... 75 more
@Repository
@Transactional
public interface AttributeRepository extends JpaRepository<Attribute, Long> {
Attribute findById(long id);
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(BoneCPDataSource ds) throws IOException {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(ds);
em.setPackagesToScan(new String[] { "org.scripps.branch.entity" });
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
return em;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
@Bean
public PlatformTransactionManager transactionManager(
EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
@Service
public interface FeatureService {
@Transactional
public List<Feature> rankFeatures(Instances data, List<String> entrezIds, Dataset d);
}
我想您忘记启用Jpa事务或将Spring数据与事务管理器相关联了:
启用事务管理:
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
Ex事务管理器与Jpa存储库相关联:
@EnableJpaRepositories(transactionManagerRef="transactionManager",
entityManagerFactoryRef="entityManagerFactory",
value="com.repositories.pkg.location" )
我正在Spring3和Hibernate3中进行产品构建,我已经更新了这个Hibernate5和Spring5。现在我可以部署应用程序了,但是当我尝试与数据库连接时,会得到“javax.persistence.TransactionRequiredException:no transaction is in progress”
GuiceModule类: 控制器类: 和StackTrace: 我做错了什么? 谢谢
当我尝试使用spring batch中的作业处理器将从csv文件恢复的一些数据持久化到我的数据库中时,控制台中会出现这个错误,对于我的dao来说,我使用的是hibernate 我已经尝试了2种方法,但同样的问题! 错误:javax.persistence.transactionRequiredException:在org.hibernate.internal.sessionimpl.checktr
场景是,我有一个带有spring批处理作业的spring启动应用程序。我正在尝试使用和使批处理作业异步,然后将此taskExecutor分配给JobLauncher。更改后,作业会异步运行,但我在持久化或更新数据库方面遇到了问题: 谢谢你的帮助!
问题内容: When I call: 我得到标题中提到的异常。 我正在使用Hibernate JPA。 问题答案: 在我自己遇到这个问题并花了几个小时试图解决这个问题之后,我终于找到了一个原因:Spring有一个错误,并且@如果同一类具有用于自动装配的注释,则无法维护带有注释的事务。 一旦从相关服务类中删除了注释,并且在XML配置中声明了一个适当的bean: 问题解决了。
我的服务(使用主数据源的jobExecutor)在从spring MVC控制器调用时运行良好,但是在从调度方法调用时始终抛出“TransactionRequiredException:没有事务正在进行”。原因看起来是从scheduledThreadPool绑定到线程的jdbcTransaction没有像localStatus那样处于活动状态。事务用于主数据源,默认情况下以DataSourceTra