0

I have an entity Car that has a nullable set of vignettes , and i want to get the Car list that haven't a vignette.

i tried with this but i don't find my way ...

Criteria criteria = getSession().createCriteria(Car.class);
criteria.createAlias("vignettes", "V");
criteria.add(Restrictions.or(Restrictions.lt("V.vignetteDateFin", dateDebut),Restrictions.eq("V.vignetteDateFin", null))) 

can you suggest any idea ?

snieguu
  • 2,073
  • 2
  • 20
  • 39

2 Answers2

1
Criteria criteria = getSession().createCriteria(Car.class);
criteria.createAlias("vignettes", "V");
criteria.add(Restrictions.or(
    Restrictions.lt("V.vignetteDateFin", dateDebut),
    Restrictions.isNull("V"))
);

If this does not do what you want you may need a subquery. See this related question: Hibernate Criteria: adding additional restriction to Restrictions.isEmpty

Community
  • 1
  • 1
carbontax
  • 2,164
  • 23
  • 37
0

I resolve this problem.

Replace this line :

criteria.add(Restrictions.or(
Restrictions.lt("V.vignetteDateFin", dateDebut),
Restrictions.isEmpty("V"))

by this one :

criteria.add(Restrictions.or(
Restrictions.lt("V.vignetteDateFin", dateDebut),
Restrictions.isNull("V"))
MKB
  • 7,587
  • 9
  • 45
  • 71