我正在使用Spring Boot 1.5.6中的spring-boot-starter-data-jpa
例如,当事务超时大于1时,一切正常
@Transaction(timeout = 2)
,@Transaction(timeout = 5)
或@Transaction(timeout = 10)
,
但是当我将它设置为@Transaction(timeout = 1)
时,它会在不到一秒的时间内抛出异常。这是我的代码的快照:
@Transactional(readOnly=true)
public interface IUserRepository extends CrudRepository<UserEntity,Long>{
@Transactional(timeout = 1)
Iterable<UserEntity> findAll();
例外是:
15:18:11.078 [http-nio-9999-exec-2] ERROR [o.a.c.c.C.[.[.[.[dispatcherServlet]:181] - Servlet.service() for servlet [dispatcherServlet] in context with path [/springJPA-LOCAL] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: nested exception is javax.persistence.PersistenceException] with root cause
javax.persistence.PersistenceException: null
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602)
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:492)
at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:50)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:329)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:504)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:489)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy198.findAll(Unknown Source)
at com.dharam.springJPA.service.impl.UserServiceImpl.doFindAll(UserServiceImpl.java:29)
at com.dharam.springJPA.Controller.SpringJPAController.startFindAll(SpringJPAController.java:39)
at com.dharam.springJPA.Controller.SpringJPAController$$FastClassBySpringCGLIB$$1b008118.invoke(<generated>)
... `
答案 0 :(得分:2)
我发现确定休眠的事务超时的逻辑存在问题。因此,提出了以下问题。 https://hibernate.atlassian.net/browse/HHH-14062?atlOrigin=eyJpIjoiNTBhZTgzODBmYTFjNDU2MDhhYzM4NjU3ZjFiYzY5NjAiLCJwIjoiaiJ9
我将直接发送PR进行修复。我不知道何时会更改它,但是如果Hibernate小组确定该错误是正确的,我认为它将很快得到解决。