我们有一个 Universe 和一个 Funkopop 。我们建立了@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;
}
我们想列出一个Universe中的所有funkopop。
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]