I have a simple native sql method as follows, which throws TransactionRequiredException since 1.2.5, which is very critical probably not only for us.

public interface PersonRepository extends JpaRepository<Person, Long> {
    @Query(value = "TRUNCATE TABLE person", nativeQuery = true)
    @Modifying
    @Transactional
    void truncate();
}

@Service
public class PersonService {
    @Autowired
    private PersonRepository dao;

    @PostConstruct
    public void init() {
        dao.truncate();
    }
}

Result: spring-boot.1.2.4.RELASE - OK spring-boot.1.2.5.RELASE - NOT OK with following error:

javax.persistence.TransactionRequiredException: Executing an update/delete query

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personService': Invocation of init method failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    ... 16 more
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query
    at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:410) ~[spring-orm-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:223) ~[spring-orm-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417) ~[spring-orm-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122) ~[spring-data-jpa-1.7.3.RELEASE.jar:?]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at com.sun.proxy.$Proxy85.truncate(Unknown Source) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_31]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_31]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_31]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    ... 16 more
Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
    at org.hibernate.jpa.spi.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:71) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_31]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_31]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_31]
    at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:362) ~[spring-orm-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at com.sun.proxy.$Proxy90.executeUpdate(Unknown Source) ~[?:?]
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$ModifyingExecution.doExecute(JpaQueryExecution.java:234) ~[spring-data-jpa-1.7.3.RELEASE.jar:?]
    at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:74) ~[spring-data-jpa-1.7.3.RELEASE.jar:?]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:99) ~[spring-data-jpa-1.7.3.RELEASE.jar:?]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:90) ~[spring-data-jpa-1.7.3.RELEASE.jar:?]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:415) ~[spring-data-commons-1.9.3.RELEASE.jar:?]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:393) ~[spring-data-commons-1.9.3.RELEASE.jar:?]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$DefaultMethodInvokingMethodInterceptor.invoke(RepositoryFactorySupport.java:506) ~[spring-data-commons-1.9.3.RELEASE.jar:?]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122) ~[spring-data-jpa-1.7.3.RELEASE.jar:?]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at com.sun.proxy.$Proxy85.truncate(Unknown Source) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_31]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_31]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_31]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    ... 16 more

Comment From: wilkinsona

Can you provide a small sample project that reproduces the problem, please?

Comment From: membersound

https://drive.google.com/file/d/0B0qVi9D7R5MZQ0xyT0VrN3RPOWs/view?usp=sharing

Just run the main class with 1.2.5.RELEASE and you get the error above. Switch to 1.2.4.RELEASE and everything works fine.

Thank you.

Comment From: wilkinsona

Thanks

Comment From: wilkinsona

There's an interesting combination of versions here:

Spring Boot Spring Framework Spring Data Result
1.2.5.RELEASE 4.1.7.RELEASE Evans-SR3 Fails
1.2.5.RELEASE 4.1.7.RELEASE Evans-SR2 Works
1.2.5.RELEASE 4.1.6.RELEASE Evans-SR3 Works
1.2.5.RELEASE 4.1.6.RELEASE Evans-SR2 Works
1.2.4.RELEASE 4.1.7.RELEASE Evans-SR3 Fails
1.2.4.RELEASE 4.1.7.RELEASE Evans-SR2 Works
1.2.4.RELEASE 4.1.6.RELEASE Evans-SR3 Works
1.2.4.RELEASE 4.1.6.RELEASE Evans-SR2 Works

The rows with the default combination of versions are in italics.

It looks like the version of Spring Boot doesn't matter and that the problem only occurs when Spring Data Evans SR3 and Spring Framework 4.1.7.RELEASE are used in combination.

Comment From: wilkinsona

@olivergierke has pointed me to DATACMNS-732 which is the cause of this problem. It's been fixed in Spring Data Gosling (which will be in Boot 1.3). You can avoid the problem when using Spring Boot 1.2.5 by using org.springframework.transaction.annotation.Transactional in place of javax.transaction.Transactional.

The underlying cause is some custom transaction handling support added in Evans SR3 which, coupled with a change in Spring Framework 4.1.7, causes support for JTA's @Transactional to be lost.

Comment From: membersound

Thanks for the quick response. We'll definitely skip 1.2.5. then as modifying all @Transactional package imports is not that suitable.

Comment From: wilkinsona

It'd be a straightforward global search and replace, but fair enough. An alternative would be to upgrade to Spring Data Fowler SR2 when it's released (currently scheduled for early next week).

Comment From: wauwau0977

Was an unexpected change for me too... The same in 1.2.6

Comment From: snicoll

I am confused. As far as I understand the problem, the transaction was not applied at all before so it's probably much worse than the exception from my perspective. Consider javax.transaction.Transactional not supported before 1.3.

Comment From: wauwau0977

I'm sorry, but I did not spend any time to investigate further. Our application is working perfectly since almost Spring Boot 1.0 till 1.2.4... Then we suddenly got that error for 1.2.5 and 1.2.6. For now to easiest for us is just to stay on 1.2.4, since we are happy with it... For 1.3 I will do some more analysis if the error still occurs.

Comment From: snicoll

It won't occur.

It looks like I didn't get the full picture of the problem but hopefully @wilkinsona was kind enough to educate me. The 1.2 line is two release trains behind and the Spring Data guys did not fix the issue in there. So if you need to upgrade 1.2 you can always override the Spring Data release train version (Fowler.SR2 typically).

Comment From: odrotbohm

I agree the situation is suboptimal as Boot 1.2 had support for the standard @Transactional and then we effectively broke it for default setup and the correct behavior can only be reinstantiated by upgrading to newer Spring Data release train.

I'll have a look at what needs to be done to back port the fix we have in Fowler and Gosling to Evans so that we could do a final service release of that which Spring Boot can upgrade then in a final service release for 1.2 itself, so that we conclude the 1.2 line in a working state.

Comment From: philwebb

I'll target this for the next 1.2.x release, hopefully it will just be a dependency upgrade.

Comment From: odrotbohm

I've back-ported the fix to Evans and it should be available for testing in Evans-BUILD-SNAPSHOT (set the property spring-data-releasetrain.version to that value).

Comment From: wilkinsona

Looks good, @olivergierke. Thank you.

Comment From: wauwau0977

Hi Team That helped. Looks all good now :+1: Good work overall, very impressed of Spring Boot. Thanks Patrick

Comment From: snicoll

Thanks for the feedback :+1:

Comment From: bytor99999

Sorry for resurrecting. We are on Boot 1.2.3 with a production app, about to do a release tomorrow, but realized we have come across this issue with a scheduled job that calls a Spring Data JPA Repository with a modifying query. Our import for @Transactional is already import org.springframework.transaction.annotation.Transactional and not sure what else we can change in the code to get it to work. Thanks.

Comment From: bytor99999

For others for future reference if the change of import doesn't work for you. I added a level of indirection. In our case we had an @Scheduled on the method too. @Transactional was at the class level, the method in the interface and @Scheduled on a single method that would call the Repository directly. So I added the level of indirection between the scheduling and the service method. Instead of them both being the same method. So I created a new bean (because of proxying), Autowired the service into it, made a method with @Scheduled on it in the new bean, and in the implementation of the method call the service method of the other class that is has the Transaction, which calls the repository. That worked perfectly.

Comment From: gitguru

This is still present in Spring Boot 1.5.2, where @Modifying queries require a org.springframework.transaction.annotation.Transactional annotation on service side.

Comment From: wilkinsona

@gitguru I suspect that problem lies in Spring Data or Spring Framework, but could you please open a new Spring Boot issue with a small sample that illustrates the problem and we can take it from there.

Comment From: odrotbohm

Actually it's just the way things work, esp. for JPA. JPA requires a transaction for modifying queries and thus the method needs to be annotated with @Transactional. We default transactions for CRUD operations but with query methods the semantics are completely in the declaration. I guess we could try meta-annotating @Modifying with @Transactional.

@gitguru — Would you mind creating a ticket for that?

Comment From: bbg3337

Commit your transaction using transaction, By this your issue will resolve.

Like. Before

sessionFactory = new HibernateUtility().getSessionFactory(); session = sessionFactory.openSession();
Query query= session.createQuery("delete from "+modelName + " "+ queryWhere ); int result = query.executeUpdate();

And after->

sessionFactory = new HibernateUtility().getSessionFactory(); session = sessionFactory.openSession(); Query query= session.createQuery("delete from "+modelName + " "+ queryWhere ); transaction = session.beginTransaction(); int result = query.executeUpdate(); transaction.commit();

Solve my issue by doing this step.

Comment From: zerkowsm

The issue seems to still exist in Spring Boot 1.5.4.RELEASE.

public interface PersonRepository extends JpaRepository<Person, Long> {
    @Query(value = "TRUNCATE TABLE person", nativeQuery = true)
    @Modifying
    void truncate();
}

@Service
public class PersonService {
    @Autowired
    private OtherService oS;

    public void init() {
        oS.init();
    }
}

@Service
public class OtherService {
    @Autowired
    private PersonRepository dao;

    @PostConstruct
    @Transactional      <----- it does not help (works fine with @Transactional over PersonService.init)
    public void init() {
        dao.truncate();
    }
}

Comment From: snicoll

@zerkowsm please read the note in this section regarding @PostConstruct. If you have more questions, please ask on StackOverflow.

Comment From: zerkowsm

@snicoll Thanks, the same situation appears when you remove @PostConstract (just used the same example).

Comment From: snicoll

@zerkowsm if you look at the history, @olivergierke has asked for an issue, I don't know if one was created. So please search or create one in their issue tracker if it's missing.

Comment From: ayushj158

I am using spring-data-JPA 2.0.7.Release and receive the same error . Using Transnational from package "org.springframework.transaction.annotation.Transactional"

Comment From: rmordillo-witbooking

Hello, I'm using SpringBoot 1.5.1.RELEASE and having the same issue. I tried with javax.transaction.Transactional and org.springframework.transaction.annotation.Transactional

with same results.

Comment From: snicoll

@rmordillo-witbooking this issue has been closed over 3 years ago. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Please ask on StackOverflow or join the community on Gitter.

Comment From: ayushj158

@rmordilo-witbooking please share your code snippet for more insight . As @snicoll mentioned you can share additional details over stack overflow and i will be happy to help .

Comment From: Teahel

Actually it's just the way things work, esp. for JPA. JPA requires a transaction for modifying queries and thus the method needs to be annotated with @Transactional. We default transactions for CRUD operations but with query methods the semantics are completely in the declaration. I guess we could try meta-annotating @Modifying with @Transactional.

@gitguru — Would you mind creating a ticket for that?

you are right.