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>
|