1

I have the next ER structure:

enter image description here

And my entities are like this:

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;
}

I want to fetch every event without quiz, so my query is this:

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

But I'm getting an empty list

I'm using hibernate for the persistence.

Somebody can help me :) ?

Rafael Carrillo
  • 2,772
  • 9
  • 43
  • 64

1 Answers1

0

Try IS EMPTY clause:

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

See this:

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

Community
  • 1
  • 1
Genzotto
  • 1,954
  • 6
  • 26
  • 45