我在jpa和hibernate中使用spring boot 2。 我尝试删除。
我的课
public Scpi{
@Id
....
private Integer id;
@ManyToMany(mappedBy = "scpi")
private Set<Asi> asi = new HashSet<>();
...
}
public Asi{
@Id
....
private Integer id;
@ManyToOne
private Spi spi;
...
}
我的删除
@Modifying
@Query("delete from Scpi scpi where scpi.id in ( select spci2.id from Scpi scpi2 inner Join spci2.asi asi inner Join asi.spi spi where spi.id= ?1)")
我得到错误
org.hibernate.hql.internal.ast.InvalidPathException:无效路径: 'spci2.asi'
有什么主意吗?
答案 0 :(得分:1)
在您的SQL中似乎有错字,应该是scpi2.asi
而不是spci2.asi
,并且与scpi2.id
相同。
因此正确的删除语句为:
@Modifying
@Query("delete from Scpi scpi where scpi.id in ( select scpi2.id from Scpi scpi2 inner Join scpi2.asi asi inner Join asi.spi spi where spi.id= ?1)")