У нас есть Вселенная и Функкоп . Мы сделали @OneToMany
отношение.
@Entity
public class Universe implements HasId{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
Integer id;
String name;
@OneToMany
List<FunkoPop> funkoPops = new ArrayList<>();
}
@Entity
public class FunkoPop implements HasId {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id = null;
private String name;
private boolean waterproof = false;
}
Мы хотим перечислить все funkopops во вселенной.
var pops = em.createQuery("SELECT u.funkoPops FROM Universe u WHERE u.name = :universeName",
FunkoPop.class)
.setParameter("universeName", "Kung-Fury")
.getResultList();
К сожалению, у нас есть:
Exception in thread "main" java.lang.IllegalArgumentException:
Type specified for TypedQuery [io.robusta.funko.entities.FunkoPop] is incompatible with
query return type [interface java.util.Collection]