-->
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.  [ 6 posts ] 
Author Message
 Post subject: Newbie HQL question
PostPosted: Mon Aug 07, 2006 4:00 am 
Newbie

Joined: Sun Aug 06, 2006 1:47 am
Posts: 8
Hi ,

I've got a domain class with other domain objects a snippet of which is ...

Code:

private Address address;
private PropertyType propertyType;
private SaleType saleType;
private Location location;
....


I would like to be able to execute some sort of query to retrieve properties as follows...

Code:
select p from property p, location l, propertytype pt, address a, saletype st where p.location.locationId = l.locationId and l.locationName = 'some location' and p.address.addressId = a.addressId and p.saleType.saleTypeId = st.saleTypeId and p.propertyType.propertyTypeId = pt.propertyTypeId

I've tried all sorts of combinations but only ever seem to get 1 property row back. Can anyone give me any pointers or advice.

thanks in advance

chris[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 5:40 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
have you tried doing some joins? for example, since property and location should be matched based on location ID, why not perform a join on that field? Same goes for address ID. salesTypeID and so on.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 6:20 am 
Newbie

Joined: Sun Aug 06, 2006 1:47 am
Posts: 8
Hi,

Yes i've tried a join on all the tables but didn't help. I am not experienced in SQL perhaps im getting the syntax could you show me an examle for location ?

i've tried HQL manual but still i'm stuck / stupid !


Top
 Profile  
 
 Post subject: Don't understand this result
PostPosted: Mon Aug 07, 2006 6:34 am 
Newbie

Joined: Sun Aug 06, 2006 1:47 am
Posts: 8
I've tried the following join where the property table has 10 rows with locationid = 1 but i only get 1 row back ?

Code:
select p from Property p inner join p.location as location where location.locationId = 1


any ideas appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 11:01 am 
Newbie

Joined: Sun Aug 06, 2006 1:47 am
Posts: 8
Ok,
I finally noticed that stupidly I've got <one-to-one relations specified in my Property.hbm.xml as below
l
Code:

      <one-to-one name="location" class="com.barrakooda.domain.Location" foreign-key="locationId"/>
      <one-to-one name="propertyType" class="com.barrakooda.domain.PropertyType" foreign-key="propertyTypeId"/>
      <one-to-one name="saleType" class="com.barrakooda.domain.SaleType" foreign-key="saleTypeId"/>
      <one-to-one name="address" class="com.barrakooda.domain.Address" foreign-key="addressId"/>



so if I change this to <many-to-one ...> how should my query look so that i get more rows. I've tried accessing p.location.locationid and this gives an error saying location isn't a field of property athough in my class it's specified.
any ideas would be great !


Top
 Profile  
 
 Post subject: solved it
PostPosted: Mon Aug 07, 2006 11:58 am 
Newbie

Joined: Sun Aug 06, 2006 1:47 am
Posts: 8
finally solved it - thanks all the same


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