Hibernate sqlRestriction query

0

Good morning I have a problem when making a query with Hibernate, the thing is that I would like to join two consultations in one and I have looked to try it with joins and others but no idea. Let the queries have if you can guide me please, what I need is the result of each of them together. Thanks in advance.

QUERY 1:

criteria.add(Restrictions.sqlRestriction(
    "id_oferta in(select idoferta from nx_ofertas_candidatos where idstudent=? and select_auto=1 and select_manual=1 and interesado=0)",
    idStudentInteres,
    Hibernate.LONG));

QUERY 2:

criteria.add(Restrictions.sqlRestriction(
    "id_oferta not in (select idoferta from nx_ofertas_candidatos where idstudent=? and nointeresado=0)",
    idStudentInteres,Hibernate.LONG));
    
asked by Oscar Marés Barrera 01.08.2018 в 11:00
source

1 answer

0

Assuming that your sqlrestriction works, you could wrap them in criteria and then use the OR condition to return the disjunction of the two expressions.

Criteria criteria = session.createCriteria(Student.class)

Criterion criterion = Restrictions.sqlRestriction("id_oferta in(select idoferta from nx_ofertas_candidatos where idstudent=? and select_auto=1 and select_manual=1 and interesado=0)", idStudentInteres, Hibernate.LONG);

Criterion criteron2 = Restrictions.sqlRestriction("id_oferta not in (select idoferta from nx_ofertas_candidatos where idstudent=? and nointeresado=0)",idStudentInteres,Hibernate.LONG);

Criteron mergeCriterion = Restrictions.or(criterion,criterion2);

criteria.add(mergeCriterion);

List list = criteria.list();
    
answered by 02.08.2018 в 09:09