我有下一个ER结构:



我的实体是这样的:

Event.java

public class Event implements Serializable {

.. many attributes here

@OneToOne(mappedBy = "evento",cascade = CascadeType.ALL,orphanRemoval = true)
     private Quiz quiz;

many getters & setters here ...

}


Quiz.java

public class Quiz implements Serializable {

    @JoinColumn(name = "evento",referencedColumnName = "id")
    @OneToOne
    private Evento evento;
}


我想获取所有事件而不进行测验,所以我的查询是这样的:

Query q = em.createQuery("SELECT e FROM Evento AS e WHERE e.encuesta IS NULL",Evento.class);


但我得到一个空名单

我正在使用休眠来保持持久性。

有人可以帮助我:)?

最佳答案

尝试IS EMPTY子句:

Query q = em.createQuery("SELECT e FROM Evento AS e WHERE e.encuesta IS EMPTY",Evento.class);


看到这个:

HQL Query to check if size of collection is 0 or empty

08-19 07:56