有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JPQL:对象列表的直接查询

我们有一个宇宙和一个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;
}

我们想列出宇宙中所有的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]

共 (0) 个答案