我有兩個物體,如下所示:
我有兩個物體。
public class EntityA
{
private String id;
private String entityId;
private String muscle;
}
public class EntityB private String id;
@ManyToOne
@JoinColumn("entitya_id")/span>
private EntityA entitya;
現在在我的EntityB repo類中,我有一個方法可以根據EntityA欄位洗掉表EntityB的行。
@modifying
@Query("DELETE FROM EntityB WHERE EntityA.entityId=:entityId AND (:muscle IS NULL OR EntityA.muscle=:muscle)")
int deleteEntityByRecords(@Param("entityId") String entityId。
@Param("muscle")String muscle)。
但是這個查詢給我帶來了一個例外:
Error creating bean with name 'EntityBrepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 驗證失敗 for query for method public abstract int com. fedex.airops.pilot.bank.PilotBankTransactionRepo.deleteEntityBRecord(java.lang.String,java.lang.String)!
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1803) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory. java:323) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5. 2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~ [spring-beans-5. 2.1.RELEASE.jar:5.2.1.RELEASE]
uj5u.com熱心網友回復:
你的查詢似乎不正確。試試下面的查詢:
@Modifying。
@Query("DELETE FROM EntityB eb WHERE eb.entitya.id=:entityId AND (:muscle IS NULL OR eb.entitya.muscle=:muscle)") /span>
int deleteEntityByRecords(@Param("entityId") String entityId。@Param("muscle")String muscle)。
uj5u.com熱心網友回復:
你也可以使用JPA倉庫:
void deleteByIdAndEntityAMuscleIsNullOrEntityAMuscle( String entityId, String muscle)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/308784.html
標籤:
上一篇:<p>我正在使用FirebaseStorage進行認證/注冊,用戶可以在注冊時上傳圖片,但我不斷收到關于<strong>用戶沒有任何權限的錯誤。</strong>當
