-->
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.  [ 8 posts ] 
Author Message
 Post subject: help with HQL and collections please
PostPosted: Tue Oct 21, 2003 10:33 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
I have a customer object which has a collection of request objects. i want a query that will return all customers that have requests with a certain property - something like

from Customer c WHERE elements(c.requests).property='value'

unfortunately, the above does not work. Does anyone know how to acomplish this with HQL?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 10:37 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
from Customer as c join c.requests as r where r.property = value;

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 5:32 am 
Newbie

Joined: Wed Oct 22, 2003 5:24 am
Posts: 5
Hi

i have the same problem with HQL and Collections.

i tried the proposal from Christian but i always get this exception:

net.sf.hibernate.QueryException: collection of values in from clause: searchat0_.searchEOList.elements [from foodexpert.model.SearchAttr as sa join sa.searchEOList as eolist where eolist.searchEO= :eoGroup]

i tried different things, none of them worked.

thanx for help!

regards pascal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 5:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
HIbernate 2.0.x doesn't allow collections of values in the from clause (only collections of entities). Hibernate 2.1 does.


Top
 Profile  
 
 Post subject: and how does this work with Maps
PostPosted: Thu Nov 13, 2003 9:18 am 
Newbie

Joined: Wed Oct 22, 2003 5:24 am
Posts: 5
hi

thanx Gavin that with the List works now. but how can i access the values of a map.

i tried everythig that is in the user guide described but nothing helped;(


i use 2.1 beta6
here my mapping:

<map name="propAmounts cascade="all">
<key column="expertobject"/>
<index column="property" type="long"/>
<element column="amount" type="float"/>
</map>


and here one of my attempts:

select food, from Food as food, food.propAmounts as pa, Property as p where pa=p.id and p.title='Vitamin' and pa.amount>12

error:
Error in DoSearchAction.perform net.sf.hibernate.QueryException: cannot derefere
nce scalar collection element: amount [select eo, pa from foodexpert.model.data.
Food as eo, eo.propAmounts as pa, foodexpert.model.data.Property as p where pa=p
.id and pa.amount = :value and p.title= :value2 order by eo.title asc]

thanx for help!

regards pascal


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 9:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Code:
select food
from Food as food, food.propAmounts as pa, Property as p
where p.title='Vitamin' and pa>12 and index(pa) = p.id


Is that what you want??

you can also write that as:

Code:
select food
from Food as food,  Property as p
where p.title='Vitamin' and food.propAmounts[p.id] >12



Finally, you can use an <index-many-to-many>, if that is more elegant.


Top
 Profile  
 
 Post subject: thanx Gavin
PostPosted: Mon Nov 17, 2003 4:49 am 
Newbie

Joined: Wed Oct 22, 2003 5:24 am
Posts: 5
hi Gavin

that was exactly was i needed. thanx a lot.

regards pascal


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 5:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No problem - Good Luck!


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