-->
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.  [ 5 posts ] 
Author Message
 Post subject: problem referencing a map element in HQL
PostPosted: Tue Nov 25, 2003 10:51 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
The query I am trying to get to work is

select r
from QuoteRequest r
where r.coverSheet.actions['Provider_In'].parameter.stringValue = '123456'

that is - each QuoteRequest has a coversheet component which has a Map called actions whose values are the parameters i am interested in

here is the mapping


<component name="coverSheet" class="com.lab.model.quote.CoverSheet">
<parent name="quoteRequest"/>
<component name="statusCode" class="com.lab.model.StatusCode">
<property name="code" column="status_code"/>
</component>
<property name="notes" column="notes"/>
<property name="lastStatusChangeTime" type="timestamp" column="last_status_change_time"/>
<property name="lastStatusCheckTime" type="timestamp" column="last_status_check_time"/>
<map name="actions" table="coveractions" lazy="true" cascade="delete">
<key column="request_id"/>
<index column="action_id" type="com.lab.model.coversheet.actions.CoverSheetAction"/>
<composite-element class="com.lab.model.Change">
<many-to-one name="initiator" class="com.lab.model.employee.Employee" column="employee_id" update="false"/>
<property name="timeStamp" column="timestamp" type="timestamp" update="false"/>
<nested-composite-element name="parameter" class="com.lab.common.Parameter">
<property name="stringValue" column="string_1" update="false"/>
<property name="dateValue" column="date_1" update="false"/>
<property name="booleanValue" column="boolean_1" update="false"/>
<property name="moneyValue" column="money_1" type="big_decimal" update="false"/>
</nested-composite-element>
</composite-element>
</map>
</component>

The query gives me a QueryException - illegally dereferenced collection element. The query I am after corresponds to the sql

select *
from quote_requests r
inner join coveractions c on r.id = c.request_id
and c.action_id = 1060
and c.string_1 = '123456'


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 11:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
what version of Hibernate? (should be 2.1beta6)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 11:22 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
yep, its 2.1beta6

BTW the CoverSheetAction class is a PersitentEnum, can I reference that in the HQL i.e actions[CoverSheetAction.PROVIDER_IN]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 11:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ok just had a quick look at the code and this syntax is not supported for composite-elements. Use:

Code:
select req
from QuoteRequest req
join req.coverSheet.actions action
where action.parameter.stringValue = '123456'
and index(action) = 'Provider_In'


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 12:20 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
Brilliant! that works well except that I have to replace the string 'Provider_In' by the actions integer id. No big deal, easy enough for me to change to integer identifiers in the queries.

thanks


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