-->
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: scroll() does not fill a one-to-many rel. as list() does
PostPosted: Tue Jul 18, 2006 10:27 am 
Newbie

Joined: Thu May 18, 2006 4:31 am
Posts: 12
Location: Germany
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-520

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


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.