title: TransactionRequiredException: Executing an update/delete query -- on jpql update query
body: <p>I get a TransactionRequiredException when trying to run update query using jpql but if I do an update using spring data provided save() method, it works fine. </p>
  
  <p><strong>My Test method:</strong></p>
  
  <pre><code>service.save(object); --- This Update works- calls spring data save()
  service.updateTable1gBycolumnpk(object);-- This update throws exception
  </code></pre>
  
  <p><strong>My service method:</strong></p>
  
  <pre><code>    @Transactional
      public int updateTable1gBycolumnpk(Table1Object object){
          return repo.updateTable1gBycolumnpk(object.getcolumnpk(), object.getname());
      }
  </code></pre>
  
  <p><strong>My Repository method:</strong></p>
  
  <pre><code>    @Modifying(clearAutomatically = true)
      @Query("UPDATE Table1 a SET a.columnpk = :columnpk WHERE a.name = :name")
      public int updateTable1gBycolumnpk(@Param("columnpk") String columnpk, @Param("name") long name);
  </code></pre>
  
  <p><strong>EDIT: Spring configuration</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans" 
      xmlns:p="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context" 
      xmlns:tx="http://www.springframework.org/schema/tx" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:jpa="http://www.springframework.org/schema/data/jpa"
      xmlns:repository="http://www.springframework.org/schema/data/repository"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/data/jpa
          http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
          http://www.springframework.org/schema/data/repository
          http://www.springframework.org/schema/data/repository/spring-repository.xsd
          "&gt;
  
      &lt;!-- Scans the classpath for annotated components that will be auto-registered as Spring beans --&gt;
      &lt;context:component-scan base-package="org" /&gt;
      &lt;!-- Activates various annotations to be detected in bean classes e.g: @Autowired --&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;!-- Start Test Configurations --&gt;
      &lt;bean id="testDataSource1" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /&gt;
          &lt;property name="url" value="jdbc:oracle:thin:@localhost:1521:ABC" /&gt;
          &lt;property name="username" value="sys as sysdba" /&gt;
          &lt;property name="password" value="SYS2013" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="entityManagerFactory" 
              class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
              p:packagesToScan="org.schema1.entities"
              p:dataSource-ref="testDataSource1"
              &gt;
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                  &lt;property name="generateDdl" value="true" /&gt;
                  &lt;property name="showSql" value="true" /&gt;
  
              &lt;/bean&gt;
          &lt;/property&gt;
          &lt;property name="jpaProperties"&gt;
                 &lt;props&gt;
                      &lt;prop key="hibernate.hbm2ddl.auto"&gt;none&lt;/prop&gt;
                      &lt;prop key="hibernate.default_schema"&gt;schema1&lt;/prop&gt;
                      &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/prop&gt;
                 &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" &gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
      &lt;/bean&gt;
      &lt;jpa:repositories base-package="org.schema1.repositories" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/&gt; 
  
  
  
  
  
      &lt;bean id="testDataSource2" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /&gt;
          &lt;property name="url" value="jdbc:oracle:thin:@localhost:1521:DEF" /&gt;
          &lt;property name="username" value="sys as sysdba" /&gt;
          &lt;property name="password" value="SYS2013" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Entity Manager Factory --&gt;
      &lt;bean id="schema2EntityManagerFactory" 
              class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
              p:packagesToScan="org.schema2.entities"
              p:dataSource-ref="testDataSource2"
              &gt;
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                  &lt;property name="generateDdl" value="true" /&gt;
                  &lt;property name="showSql" value="true" /&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
          &lt;property name="jpaProperties"&gt;
                 &lt;props&gt;
                      &lt;prop key="hibernate.hbm2ddl.auto"&gt;none&lt;/prop&gt;
                      &lt;prop key="hibernate.default_schema"&gt;schema2&lt;/prop&gt;
                      &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/prop&gt;
                 &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  
      &lt;bean id="schema2TransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="schema2EntityManagerFactory" /&gt;
      &lt;/bean&gt;
  
      &lt;jpa:repositories base-package="org.schema2.repositories" entity-manager-factory-ref="schema2EntityManagerFactory" transaction-manager-ref="schema2TransactionManager"/&gt;
  
      &lt;!-- enable the configuration of transactional behavior based on annotations --&gt;
      &lt;tx:annotation-driven /&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Stacktrace:</strong></p>
  
  <pre><code>Exception in thread "main" 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:413)
      at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:246)
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:491)
      at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
      at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:131)
      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.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
      at com.sun.proxy.$Proxy40.updateTable1gBycolumnpk(Unknown Source)
      at org.frb.stls.ginvoicing.apputils.processor.services.dag.DagShdServiceImpl.updateDagShdBycolumnpk(DagShdServiceImpl.java:51)
      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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
      at com.sun.proxy.$Proxy42.updateDagShdBycolumnpk(Unknown Source)
      at test.Test.processorSchematest(Test.java:97)
      at test.Test.main(Test.java:54)
  Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
      at org.hibernate.jpa.spi.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:71)
      at org.springframework.data.jpa.repository.query.JpaQueryExecution$ModifyingExecution.doExecute(JpaQueryExecution.java:238)
      at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:78)
      at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:100)
      at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:91)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:462)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440)
      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:281)
      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)
      ... 23 more
  </code></pre>