-->
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: problem with loading associations
PostPosted: Wed Nov 25, 2009 11:54 am 
Newbie

Joined: Wed Nov 25, 2009 11:35 am
Posts: 17
Hello

I need to load table 'T1' with table 'T2' connected via many-to-one using left join (coz there can be no rows in T2 for given T1 row).

When I do:
Code:
Criteria crit = session.createCriteria(T1.class);
        crit.add( Expression.eq(...) );
        crit = crit.createCriteria("dttrintnSet", CriteriaSpecification.LEFT_JOIN); // dttrintn is a Set of T2 in T1.
        crit.list();

everything looks fine. However i need to do:
Code:
ScrollableResults sr = crit.scroll(ScrollMode.FORWARD_ONLY);
         while( sr.next() ) {
              T1 obj = (T1) sr.get(0);
              Set t2set = obj.getDttrintnSet();
              //some logic
              session.evict(obj);
         }

because table size is too big and can't be loaded fully via .load (getting heap error).
In second example I'm always getting t2set item count 1 which is first one in collection. (So )

How can i access proper T2 instances on each iteration of "while( sr.next() )" ?


Below is actual code and output:
Code:
      Integer btintn = new Integer(19454/*12503*/) ;
      Criteria crit = session.createCriteria(Transforbatchview.class);
      crit.add( Expression.eq("trbtintn", Batch.get(session, btintn)) );
      crit.addOrder(Order.asc("trintn"));
      crit = crit.createCriteria("dttrintnSet", CriteriaSpecification.LEFT_JOIN);
      ScrollableResults sr = crit.scroll(ScrollMode.FORWARD_ONLY);
      while( sr.next() ) {
         Transforbatchview tv = (Transforbatchview) sr.get(0);
         Dettransforbatchview dt = (Dettransforbatchview) tv.getDttrintnSet().toArray()[0];
         System.out.println( "n " + sr.get().length + " trans " + tv.getTrintn() + " dettrans " + dt.getId().getDtintn() );
      }


Output:
n 1 trans 273313 dettrans 223661
n 1 trans 273315 dettrans 223664
n 1 trans 273315 dettrans 223664 // expected dettrans 223665
n 1 trans 273316 dettrans 223666
n 1 trans 273318 dettrans 223667
n 1 trans 273318 dettrans 223667 // expected dettrans 223668
n 1 trans 273320 dettrans 223671
n 1 trans 273320 dettrans 223671 // expected dettrans 223662


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.