-->
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.  [ 1 post ] 
Author Message
 Post subject: Help needed with HQL Joined Vieiw on same table
PostPosted: Tue Jul 11, 2006 5:45 am 
Newbie

Joined: Tue Jul 11, 2006 5:14 am
Posts: 1
I am attempting to write an Oracle query in HQL which is basically a joined view on the same table. I can generate the queries on the database using SQL in TOAD and they work fine, but I am finding it impossible to write the correct HQL query for use in Hibernate.

The query in SQL run through TOAD looks like this:-

--This one works but I assume we can't use the (+) notation in Hibernate queries
select a.label_id,a.text,a.locale, b.locale, b.text
from ITC_LABELS a, ITC_LABELS b where
a.label_id = b.label_id(+)
and a.label_id like 'Admin%'
and a.locale = 'uk'
and b.locale(+) = 'sg'

so here is a version in ansi SQL - not using the (+) syntax which also works:-

select a.label_id,a.text,a.locale, b.locale, b.text
from ITC_LABELS a left outer join ITC_LABELS b on
(a.label_id = b.label_id and b.locale = 'sg')
where a.label_id like 'Admin%'
and a.locale = 'uk'

Now here is my attempt using HQL through JAVA language:-

String QueryStr = "select a.status, a.labelName, a.text, b.text from ItcLabel a left outer join ItcLabel as b on (a.labelName = b.labelName and b.locale = '"+selectedLocale+"') where a.labelName like '"+labelName+"' and a.locale = '"+userLocale+"'";
System.out.println(QueryStr);
Query q = hs.createQuery(QueryStr);

(Some of the field names are different but that is only because they have different mapped names.)

I am getting the following error when I try this:-

2006-07-10 10:09:55,576 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/shape].[action]] Servlet.service() for servlet action threw exception
org.hibernate.hql.ast.QuerySyntaxError: unexpected token: on near line 1, column 134 [select a.status, a.labelName, a.text, b.text from com.electrocomponents.broadvision.itc.dao.ItcLabel a left outer join ItcLabel as b on (a.labelName = b.labelName and b.locale = 'sg') where a.labelName like 'admin' and a.locale = 'uk']
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:215)

Any help you can give would be greatly appreciated. Many thanks.


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

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.