您现在的位置是:首页 > 文章详情

Spring Data之@Query中的org.hibernate.hql.internal.QueryExecutionRequestEx...

日期:2018-04-12点击:349

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

1.问题描述

 org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [update com.easy.springboot.demo_cache.User a set a.password = :password where id=:id] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.errorIfDML(QueryTranslatorImpl.java:311) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:362) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final] at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1489) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final] 
  1. 问题分析
    从错误信息中,可以发现,@Query无法进行DML操作,该如何做呢?

  2. 问题解决

添加 @Modifying 注解:

package com.easy.springboot.demo_cache import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.Modifying import org.springframework.data.jpa.repository.Query import org.springframework.data.repository.query.Param interface UserDao : JpaRepository<User, Long> { @Query("update #{#entityName} a set a.password = :password where id=:id") @Modifying fun updatePassword(@Param("id") id: Long, @Param("password") password: String): Int } 
原文链接:https://yq.aliyun.com/articles/626969
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章