boa tarde , minha duvida é a seguinte, quero fazer com que uma query que devolva para mim registros de pais que tenham mais que um filho,
@Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
}
@Entity public class Father extends Parent {
@OneToMany(mappedBy = "father",cascade = CascadeType.ALL)
private List<Child> childs = new ArrayList<>();
}
@Entity public class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@ManyToOne
private Father father;
@ManyToOne
private Mother mother;
}
QUERY :
@Query("select f.name ,count ( f.childs )from Father f group by f.name having count (f.childs)") Page countFatherByChilds(Pageable pageable );
sempre que tento isso estou tendo null exception mas tenho uma script do banco para fazer insert que funciona.