Lovecraftian: hibernate HQL IS EMPTY not working and makes absurdly complex SQL

Hello,

This is the story: I have one for many. one of which is "RadicadoOficio" and many of them are "RespuestaOficio"

I just want to choose everyone who has no options.

These are the entities (abbreviated for educational purposes):

@Entity @Table(name="COR_RADICADO_OFICIO") public class RadicadoOficio { @OneToMany(mappedBy="radicado") private List<RespuestaOficio> respuestas; @Column(name="requiere_respuesta") private Long requiereRespuesta; } @Entity @Table(name="cor_respuesta_oficio") public class RespuestaOficio { @ManyToOne @JoinColumns({@JoinColumn(name = "num_radicado"), @JoinColumn(name="ano_radicado")}) private RadicadoOficio radicado; } 

This DAO Method:

 HibernateUtil.getCurrentSession().createQuery("select obj from " + sample.getCanonicalName() + " obj where obj." + longProp+ " = ? and obj." + childrenProp + " IS EMPTY" ) .setLong(0, longVal ); if (firstResult != null) { q.setFirstResult(firstResult); q.setMaxResults(maxResults); } return q.list(); 

Displays this material:

select * from (select a row _. *, rownum rownum_ from (select radicadoof0_.ANO_RADICADO how ANO1_8_, radicadoof0_.NUM_RADICADO how NUM2_8_, radicadoof0_.anexos how anexos8_, radicadoof0_.antecedentes how antecede4_8_, radicadoof0_.asunto asunto8_, radicadoof0_.complemento_direccion and compleme6_8_, radicadoof0_.estado_radicado like estado7_8_, radicadoof0_.fecha_radicado like fecha8_8_, radicadoof0_.fecha_recibido like fecha9_8_, radicadoof0_.fecha_registro like fecha10_8_, radicadoof0_.fecha_vencimiento like fecha11_8_, radicadoof0_.folios like folios8_, radicadoof0_.INTERNO_FUNCIONARIO like INTERNO19_8_, radicadoof0_.INTERNO_ESTATUS like INTERNO13_8_, radicadoof0_. item, like item8_, radicadoof0_.num_planilla as num14_8_, radicadoof0_.num_respuesta as num15_8_, radicadoof0_.INTERNO_PETICIONARIO, like INTERNO21_8_, radicadoof0_.requiere_respuesta0erereres_rereres_rererere_rererere_rererere_rererere_rereu_rere_rere_rere_rere_repreest_rerei_rerei_rerei_rerei_rerei puesta17_8_, radicadoof0_.tipo_aplicativo as tipo18_8_ of COR_RADICADO_OFICIO radicadoof0_ where radicado of0_.requiere_respuesta =? and no (exists (select respuestas1_.INTERNO_RESPUESTA from cor_respuesta_oficio respuestas1_, where radicadoof0_.ANO_RADICADO = respuestas1_.num_radicado and radicadoof0_.NUM_RADICADO = respuestas__ = rowu) =))) and rownum_>?

and the oracle gives an "invalid number" error, which I don’t understand.

any help is appreciated tnx

+4
source share
1 answer

Your hql can be changed to what is lower along with your options. Here you should use all the elements in hql.

 createQuery("select r FROM RadicadoOficio r where 0 = all elements(r.respuestas)"); 

So, your request will look like below

 HibernateUtil.getCurrentSession().createQuery("select obj from " + sample.getCanonicalName() + " obj where obj." + longProp+ " = ? and 0=all elements(obj." + childrenProp + ")" ) .setLong(0, longVal ); 
0
source

All Articles