-->
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: Query to get last element of composite-element list?
PostPosted: Fri Mar 05, 2004 6:40 pm 
Newbie

Joined: Sat Jan 10, 2004 10:06 pm
Posts: 9
Location: Calgary, AB, Canada
Hi Folks,

I wish to write a query to get the very last element of a composite-element list. Sure, we can just get the list and then get the size()-1 element, but this list will likely be large and we don't want to read the whole list into memory just to get the last element. If I use lazy="true" I can avoid reading the list early, but it appears getting the last element then brings in the whole list before returning the last element.

So I tried a query! From the HBM class description below, I have ScheduleTimer containing a list of TimerHeartBeats. I have tried several combinations of query to get the last item, but they all fail - it seems that Hibernate wants the TimerHeartbeat to be an entity???

From the manual, I found a query that seemed to do what I wanted, so from that as a template I wrote

select
heartbeat
from
SchedulerTimer timer join timer.heartbeats
where
timer.heartbeats[ size(timer.heartbeats) - 1 ] = heartbeat

but Hibernate complains with:

"path expression ended in composite collection element"

How can I get the last element in the timer.heartbeats list as a query - OR... how can I get the last element while avoiding loading the whole list?

Regards
Jay


-----------------------------------------------------------------------

<class name="SchedulerTimer" table="SCHEDULER_TIMER">
<id name="id" column="id" type="long">
<generator class="increment"/>
</id>
<property name="schedulerName" not-null="true"/>
<list name="heartbeats" table="HEARTBEAT" lazy="true" >
<key column="SCHEDULER_TIMER_ID"/>
<index column="IDX"/>
<composite-element class="TimerHeartbeat">
<property name="messageDate" not-null="true"/>
<many-to-one name="schedulerTimer" not-null="true"/>
</composite-element>
</list>
</class>


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.