-->
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: newbie HQL questions ( trying to execute join )
PostPosted: Thu Mar 01, 2007 4:22 am 
Newbie

Joined: Thu Mar 01, 2007 4:13 am
Posts: 4
I am trying to duplicate an HQL join example from the manual as below
in my code but am having no luck, to pull data from two related tables via a join

http://www.hibernate.org/hib_docs/v3/re ... ryhql.html
select cust
from Product prod,
Store store
inner join store.customers cust
where prod.name = 'widget'
and store.location.name in ( 'Melbourne', 'Sydney' )
and prod = all elements(cust.currentOrder.lineItems)

and am trying to do similar, and select data from both tables only for
a specific country.

I have two tables

DATATYPE :
hjid bigint NOT NULL ( KEY )
hjtype character varying(255) NOT NULL
country character varying(255)
comments character varying(255)
programme character varying(255)

REVENUECOSTSFUELTYPE :
hjid bigint NOT NULL
hjtype character varying(255) NOT NULL
type character varying(255)
comments character varying(255)
value real
samplingparams bigint
datatype_revenuecostsfuel_hjid bigint ( FOREIGN_KEY FOR DATATYPE TABLE)
datatype_revenuecostsfuel_hjindex
grouping bigint


My query is

'select data from generated.DATA data inner join
generated.REVENUECOSTSFUEL sub on data.hjid =
sub.datatype_revenuecostsfuel_hjid and data.COUNTRY=spain

i get :
<java.lang.Exception: java.lang.Exception: java.lang.Exception: Error
looking for existing data :
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: where
near line 1, column 80


I would be glad for any assistance

Thanks

Paul.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 01, 2007 5:01 am 
Newbie

Joined: Sun Oct 08, 2006 8:03 am
Posts: 14
Have you tried something like:

Code:
select data
from generated.DATA data, generated.REVENUECOSTSFUEL sub
where
   data.hjid = sub.datatype_revenuecostsfuel_hjid
and
   data.COUNTRY=spain


I think the HQL Reference Manual section 14.8 http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html#queryhql-select is useful
Code:
select foo
from Foo foo, Bar bar
where foo.startDate = bar.date


John.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 01, 2007 5:04 am 
Newbie

Joined: Mon Feb 19, 2007 12:54 am
Posts: 16
Location: banglore, india
'select data from generated.DATA data inner join
generated.REVENUECOSTSFUEL sub on data.hjid =
sub.datatype_revenuecostsfuel_hjid and data.COUNTRY=spain

Here spain is string put that in ' (single quotes)

Change to following and check

'select data from generated.DATA data inner join
generated.REVENUECOSTSFUEL sub on data.hjid =
sub.datatype_revenuecostsfuel_hjid and data.COUNTRY='spain'

_________________
Banglore Developer


Top
 Profile  
 
 Post subject: check the query
PostPosted: Thu Mar 01, 2007 5:06 am 
Newbie

Joined: Mon Feb 19, 2007 12:54 am
Posts: 16
Location: banglore, india
single quote is missing for spain

_________________
Banglore Developer


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.