-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Problem with joins in hql
PostPosted: Mon Apr 18, 2011 11:16 pm 
Newbie

Joined: Mon Apr 18, 2011 11:06 pm
Posts: 1
Hi, Im having so many trouble to pass from sql to hql.

The query is

select
distinct E.CODIGO_ENTIDAD CODIGO_UDAF, e.razon_social NOMBRE_UDAF, e.nemonico_entidad NEMONICO_UDAF,
E.RUC_ENTIDAD RUC_UDAF
from
Entidad e
LEFT JOIN Relacion_Entidad a ON e.codigo_Entidad=a.entidad_A AND a.codigo_Tipo_relacion=33
LEFT JOIN
( select substr(nemonico_Entidad,0,length(nemonico_Entidad)-4) Nemonico
from Entidad
where nemonico_Entidad not like '%0000' ) T ON substr(e.nemonico_Entidad,0,length(e.nemonico_Entidad)-4) = Nemonico
where
e.nemonico_Entidad like '%0000' and
length(e.nemonico_Entidad)>5

I've got a problem (path expected for join). when I try to
do the HQL

select
distinct E.CODIGO_ENTIDAD CODIGO_UDAF, e.razon_social NOMBRE_UDAF, e.nemonico_entidad NEMONICO_UDAF,
E.RUC_ENTIDAD RUC_UDAF
from
Entidad e
LEFT JOIN Relacion_Entidad a
LEFT JOIN
( select substring(nemonico_Entidad,0,length(nemonico_Entidad)-4) Nemonico
from Entidad
where nemonico_Entidad not like '%0000' ) T
where
e.codigo_Entidad=a.entidad_A AND a.codigo_Tipo_relacion=33
and substring(e.nemonico_Entidad,0,length(e.nemonico_Entidad)-4) = Nemonico
and
e.nemonico_Entidad like '%0000' and
length(e.nemonico_Entidad)>5




Hope someone can help me.


Thanks in advance!


Top
 Profile  
 
 Post subject: Re: Problem with joins in hql
PostPosted: Tue Apr 19, 2011 3:21 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 3:31 am
Posts: 41
Hi

Check this

Join HQL

_________________
Thanks
Niki


Top
 Profile  
 
 Post subject: Re: Problem with joins in hql
PostPosted: Tue Apr 19, 2011 8:30 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
Hi,

You can only join entities linked to each other through the hibernate mapping (hbm file or annotations)
And then you need to specify the path of this link in the join condition, so you will get something like that:

SELECT ... FROM Entidad e LEFT JOIN e.XXX.YYY.Relacion_Entidad a ON a.codigo_Tipo_relacion=33

Also the condition e.codigo_Entidad=a.entidad_A is no longer needed, hibernate will generate it automatically on its own

@niks23: once again very helpful post!!


Top
 Profile  
 
 Post subject: Re: Problem with joins in hql
PostPosted: Wed Apr 20, 2011 5:49 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 3:31 am
Posts: 41
@ overmeulen

Thanks

_________________
Thanks
Niki


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.