【发布时间】:2021-11-10 20:01:49
【问题描述】:
我有两个实体如下:
public class EntityA
{
private String id;
private String entityId;
private String muscle;
}
public class EntityB
{
private String id;
@ManyToOne
@JoinColumn("entitya_id")
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: Validation failed for query for method public abstract int com.fedex.airops.pilot.bank.PilotBankTransactionRepo.deleteEntityBRecord(java.lang.String,java.lang.String)!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1803) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at 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]
【问题讨论】:
标签: java spring-boot