Hibernate version:
3.1.3
Name and version of the database you are using:
Oracle 8.1.7/9i
Hello,
I am facing different results between 1) iterating through a ScrollableResult and adding the objects to a result list and 2) call list() on the query.
The starting point is a parent/child relationship: a message has a collection of recipients (in German: Nachricht=message and Empfaenger=recipient).
Requirements are
a) filter the resulting messages by properties of a message, e.g. by customerId and time constraints
b) filter the resulting messages by properties of
the recipients, e.g. by the recipient's number
c) get only a certain range of messages, e.g. the first 10 messages
d) eagerly fetch the recipients of a message
The relationship from message to recipient is a usual one-to-many-relationship.
Code:
<set name="empfaenger" table="nachricht_fahrzeug" lazy="true" cascade="none">
<key column="id_nachricht" />
<one-to-many class="NachrichtAnFahrzeug" />
</set>
The Hibernate query is as follows:
Code:
FROM Nachricht nr JOIN FETCH nr.empfaenger WHERE nr.kundenId = :k AND nr.empfaenger.empfaengerNr = :fnr
Now when scrolling through the resultset I receive the correct List<Nachricht>, but the recipients-Collection of a message is always of size one! This is the problem I am facing right now. Requirements a), b) and c) I seem to have met.
When calling q.list(), the result is as desired. But I cannot use q.list() because of requirement c).
BTW: I do not use q.setMaxResults() / q.setFirstResult() as it does not correctly narrow the resultset as desired - see
http://opensource.atlassian.com/project ... wse/HB-520Code:
int NUM_OBJECTS = ...;
Query q = ...;
ScrollableResults scroll = q.scroll();
scroll.beforeFirst();
List<Nachricht> nachrichten = new ArrayList<Nachricht>();
int i=0;
while( ( NUM_OBJECTS > i++ ) && scroll.next() ){
Nachricht nachricht = (Nachricht) scroll.get(0);
nachrichten.add(nachricht);
}
scroll.close();
return nachrichten;
Any ideas how to fetch the recipients collection in this special case?
Best regards,
Jan