Spring Data之@Query中的org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML

原创 2015年03月04日 20:36:48

1. 环境准备

   Spring , Spring Data, JPA, HIbernate, JDK 1.7

2.  问题提出

   在使用Spring Data 来更新数据之时,爆出了如下错误信息:

@Query("UPDATE User u SET u.state = ?1 WHERE u.server.id = ?2")
public void updateAllUsers(long state, long serverid);

错误信息如下:

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [ update OrderEntity entity set entity.order_status = :status where entity.id = :orderId]; nested exception is java.lang.IllegalStateException: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [ update com.creditease.bsettle.pay.model.OrderEntity entity set entity.order_status = :status where entity.id = :orderId]
	at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:293)
	at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:108)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:403)
	at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
	at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
	at $Proxy70.updateOrderStatus(Unknown Source)
	at com.creditease.bsettle.pay.repository.OrderEntityRepositoryTest.testUpdateStatus(OrderEntityRepositoryTest.java:71)
	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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalStateException: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [ update OrderEntity entity set entity.order_status = :status where entity.id = :orderId]
	at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:310)
	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.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:311)
	at $Proxy90.getSingleResult(Unknown Source)
	at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:168)
	at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:59)
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:97)
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:88)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:384)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
	... 38 more
Caused by: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [ update OrderEntity entity set entity.order_status = :status where entity.id = :orderId]
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.errorIfDML(QueryTranslatorImpl.java:291)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:340)
	at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:198)
	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1194)
	at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
	at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:287)
	... 56 more
3. 问题分析

  从错误信息中,可以发现,@Query无法进行DML操作,该如何做呢?

4. 问题解决

@Modifying
@Query("UPDATE User u SET u.state = ?1 WHERE u.server.id = ?2")
public void updateAllUsers(long state, long serverid);


学习Spring JPA时报的Not supported for DML operations 错误

在运行JPA修改数据代码报 Not supported for DML operations 错误 @Query(value = "update User user set user.ad...
  • lx_yoyo
  • lx_yoyo
  • 2017年06月03日 20:53
  • 2199

org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations

今天在写数据接口的时候,涉及到数据库操作,在使用Spring Data更新数据时,意外的出现了如下错误: 源代码 @Query("update WarningMonitor w se...
  • hh12211221
  • hh12211221
  • 2016年12月22日 17:44
  • 1047

Spring Data之@Query中的org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML

1. 环境准备    spring , Spring Data, JPA, hibernate, JDK 1.7 2.  问题提出    在使用Spring Data 来更新数据...
  • weixin_36667844
  • weixin_36667844
  • 2017年03月15日 11:22
  • 371

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: table is not Mapped问题解决

引言: 在基于SpringData/JPA来快速开发若干功能过程中,碰到了table is not Mapped问题,经过一番辛苦的调试测试之后,才发现了一个@Entity的属性name的妙用。...
  • blueheart20
  • blueheart20
  • 2015年02月04日 14:28
  • 31568

Can not issue data manipulation statements with executeQuery()错误解决

强烈建议:尽信书,不如无书!!!    下午没事,就练习了下连接数据库,结果发现了一个问题,哈哈 Can not issue data manipulation statements with ...
  • cherishme1988
  • cherishme1988
  • 2012年03月27日 15:47
  • 49908

hibernate异常:org.springframework.dao.InvalidDataAccessApiUsageException解决办法

org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient i...
  • Cheung1021
  • Cheung1021
  • 2011年05月26日 21:49
  • 16310

org.springframework.dao.InvalidDataAccessApiUsageException

  • 2017年08月20日 13:48
  • 124KB
  • 下载

【other】CSDN - 文章导出API

API - CSDN接口简介获取CSDN指定页数的博客内容。返回一个json数据,可以用于博客数据导出或者博客搬家等。 可以生成包含博客内容的json文件。 使用方法 请求地址: http://yao...
  • wxgxgp
  • wxgxgp
  • 2018年02月11日 17:48
  • 35

Supported Values for @SuppressWarnings

If you are a Java developer and use the new @SuppressWarnings annotation in your code from time-to-t...
  • lvzhuyiyi4
  • lvzhuyiyi4
  • 2013年10月10日 09:21
  • 492

spring data jpa 使用(一)

Spring 的一个子项目。用于简化数据库访问,支持NoSQL 和 关系数据存储。其主要目标是使数据库的访问变得方便快捷。...
  • qq_37334135
  • qq_37334135
  • 2017年08月29日 15:58
  • 174
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Spring Data之@Query中的org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML
举报原因:
原因补充:

(最多只允许输入30个字)