我有两个实体A和B,如下所示:
@Entity
public class A {
@Id
private int id;
private String name;
private boolean hasFailedChild;
@OneToMany
private List<B> bs;
public A(String name, long count) {
this.name = name;
this.hasFailedChild = (count > 0);
}
}
@Entity
public class B {
@id
private int id;
private String name;
private String status;
@ManyToOne
private A a;
//required constructors
}
我正在尝试使用@Query以A
状态获取所有B
及其计数Failed
。
我已经尝试过以下查询:
public interface ARepository extends CrudRepository<A, Integer> {
@Query(value = "select new A(a.name, count(b)) " +
"from A a left join a.bs b where b.status = 'Failed'")
List<A> findAllA();
}
但是,它不起作用。有人可以在这里帮助我。
您应通过以下方式更正您的查询: