-->
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.  [ 2 posts ] 
Author Message
 Post subject: Translating SQL Query to HQL Query/Projection Criteria
PostPosted: Wed Mar 12, 2008 3:59 pm 
Newbie

Joined: Fri Feb 22, 2008 9:40 am
Posts: 7
How to translate the following SQL Query to HQL or Projection Criteria ?

Code:
select
   e.id
   , e.num_position
   , ts.lang_id as default_lang_id
   , ts.localized_text as default_text
   , ts2.lang_id as translation_lang_id
   , ts2.localized_text as translation
from estrato e
left outer join textsnippet ts on ts.ref_id = e.id and ts.ntype = 2 and ts.lang_id = 14
left outer join textsnippet ts2 on ts2.ref_id = e.id and ts2.ntype = 2 and ts2.lang_id in (34,36)
where e.container_id = 548


I'm trying to do this, but is the first time I need to write a query in HQL/Criteria that has 2 joins on the same entity and the join clause is kinda "special".

I've written the following HQL but it's not working as expected.

Quote:
select e.Id, s.LocalizedText, s2.LocalizedText from Estrato e
left outer join e.Snippets s
left outer join e.Snippets s2
where e.Container.Id = 548 and s.Language.Id = 14 and (s2 is null or s2.Language.Id in (34, 36))



Cheers,

Felipe Garcia
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 1:16 pm 
Beginner
Beginner

Joined: Sun Oct 22, 2006 12:06 pm
Posts: 39
You can also use the plain sql query for this job.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.