Spring boot Spring数据JPA:DML操作不支持
我在扩展Spring boot Spring数据JPA:DML操作不支持,spring-boot,spring-data,spring-data-jpa,jpql,amazon-aurora,Spring Boot,Spring Data,Spring Data Jpa,Jpql,Amazon Aurora,我在扩展crudepository的界面中为Amazon Aurora DB编写了一个查询,以删除一些对象,但是当我执行该查询时,它抛出了一个异常 @Transactional @Query("delete from HotelPrice hp where hp.updateDate < ?1 ") void deletePriceOlderThan (Date date); @Transactional @查询(“从HotelPrice hp删除,其中hp.updateDate
crudepository
的界面中为Amazon Aurora DB编写了一个查询,以删除一些对象,但是当我执行该查询时,它抛出了一个异常
@Transactional
@Query("delete from HotelPrice hp where hp.updateDate < ?1 ")
void deletePriceOlderThan (Date date);
@Transactional
@查询(“从HotelPrice hp删除,其中hp.updateDate<?1”)
作废删除价格奥尔德坦(日期);
异常的跟踪:
Caused by: java.lang.IllegalStateException: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [delete from com.gamesa.backend.persistence.domain.backend.HotelPrice hp where hp.updateDate < ?1 ]
at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:554)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:208)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:87)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:116)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:106)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:499)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:477)
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)
... 35 common frames omitted
原因:java.lang.IllegalStateException:org.hibernate.hql.internal.QueryExecutionRequestException:不支持DML操作[从com.gamesa.backend.persistence.domain.backend.HotelPrice hp where hp.updateDate中删除]
位于org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:554)
位于org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:208)
位于org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:87)
位于org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:116)
位于org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:106)
位于org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:499)
位于org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:477)
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:179)上
位于org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56)
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:179)上
位于org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
位于org.springframework.transaction.interceptor.TransactionSpectSupport.invokeWithinTransaction(TransactionSpectSupport.java:282)
位于org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:179)上
位于org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
... 省略35个公共框架
通过使用@modifying注释查询方法,实现执行实际上只需要参数绑定的修改查询
@修改有效地删除EntityManager中仍挂起的所有未刷新的更改。如果不希望自动清除EntityManager,可以将@Modifying annotation的clearAutomatically属性设置为false
工作守则如下:
@Transactional
@Modifying
@Query("delete from HotelPrice hp where hp.updateDate < ?1 ")
void deletePriceOlderThan (Date date);
@Transactional
@修改
@查询(“从HotelPrice hp删除,其中hp.updateDate<?1”)
作废删除价格奥尔德坦(日期);
进一步阅读:
1. 你能为例外添加堆栈跟踪吗?如果你能在delete方法上添加“@Modifying”,这将有效地删除EntityManager中所有尚未刷新的更改。如果不希望自动清除EntityManager,可以将@Modifying annotation的clearAutomatically属性设置为false@Yogi,很有效,谢谢。请转换为答案可能会被视为@enLopes的副本-添加我的评论作为答案