-->
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.  [ 2 posts ] 
Author Message
 Post subject: Empty children under a parent but the ResultSet isn't empty!
PostPosted: Tue Jan 11, 2005 9:58 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Hi I think I have a newbie problem... I use Hibernate 1.0.2 1 year ago, It wors well, and I try now to use the 3.0 beta for some prototyping.

I just try to get a collection of "children" linked to a "parent".

If I try to load a Parent or a Child by using the primary key it works well, I only have problem to get all children from a specific parent.

When I put the debug mode for JDBC binding of Hibernate I see all records of children being read from the database... more than 200 record of children... So the mapping xml must be correct ? right? But when I am doing the parent.getChildren.getSize() I get 0 children! I dont understand why the children are not added to the Set of Children in the Parent class.

I check the HashCode method of the children value :

Code:
public int hashCode() {
   int i = new HashCodeBuilder(17, 37).append(getUniqueId()).toHashCode();
   return i;
}


and the debugger shows me that all hashCode were unique for all 200 records. All children should be add in the children Set of the parent classe?

Any idea?

Thanks for Answering

Etienne
Montreal

Hibernate version: 3.0 beta

Name and version of the database you are using: DB2 AS400



The generated SQL (show_sql=true):

select Childrens0_.trpgcd as trpgcd__, Childrens0_.trafnb as trafnb__, Childrens0_.trafnb as trafnb0_, Childrens0_.tregdc as tregdc5_0_, Childrens0_.trehdc as trehdc5_0_, Childrens0_.trpmcd as trpmcd5_0_, Childrens0_.trahqy as trahqy5_0_, Childrens0_.traiam as traiam5_0_, Childrens0_.trpncd as trpncd5_0_, Childrens0_.trg9cd as trg9cd5_0_, Childrens0_.trc1st as trc1st5_0_, Childrens0_.trpgcd as trpgcd5_0_ from childrenTable Childrens0_ where Childrens0_.trpgcd=?


20:23:15,716 DEBUG BigDecimalType:68 - returning 'Good_Child_ID' as column: trafnb0_
20:23:15,716 DEBUG StringType:68 - returning '20050103' as column: tregdc5_0_
20:23:15,716 DEBUG StringType:68 - returning '20050106' as column: trehdc5_0_
20:23:15,716 DEBUG StringType:68 - returning '12345 ' as column: trpmcd5_0_
20:23:15,716 DEBUG StringType:68 - returning '3080.000' as column: trahqy5_0_
20:23:15,716 DEBUG StringType:68 - returning '123.12' as column: traiam5_0_
20:23:15,716 DEBUG StringType:68 - returning 'ok' as column: trpncd5_0_
20:23:15,716 DEBUG StringType:68 - returning 'ok' as column: trg9cd5_0_
20:23:15,716 DEBUG StringType:68 - returning '...' as column: trc1st5_0_
20:23:15,716 DEBUG StringType:68 - returning 'good data ' as column: trpgcd5_0_
20:23:15,716 DEBUG StringType:68 - returning 'good data ' as column: trpgcd__
20:23:15,732 DEBUG BigDecimalType:68 - returning 'Good_Child_ID' as column: trafnb__
[...]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 2:53 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Hi all,

I am still using ibernate 3.0 and it seems that I have a problem when initialising a simple collection.

I try to load a collection of 4 trades (children) linked to a Account (Parent). When I debug the Hibernate code, I see that all Trades are loaded, but at the at the end, when I am doing account.getTrades.size() I have a 0 and not a 4!!

I dont see what I am doing wrong. I am using a DB2 database on AS400. I have done this many time on others database. It is very strange.
Here's the stdout of the debugging console:
Code:

13:28:00,866 DEBUG LongType:68 - returning '67105965' as column: trafnb__
13:28:00,866 DEBUG DefaultLoadEventListener:185 - loading entity: [Trade#67105965]
13:28:00,866 DEBUG DefaultLoadEventListener:200 - entity found in session cache
13:28:00,866 DEBUG DefaultLoadEventListener:291 - attempting to resolve: [Trade#67105965]
13:28:00,881 DEBUG DefaultLoadEventListener:300 - resolved object in session cache: [Trade#67105965]
13:28:00,881 DEBUG Loader:381 - done processing result set (4 rows)
13:28:00,881 DEBUG AbstractBatcher:275 - about to close ResultSet (open ResultSets: 1, globally: 1)
13:28:00,881 DEBUG AbstractBatcher:260 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
13:28:00,897 DEBUG AbstractBatcher:361 - closing statement
13:28:00,912 DEBUG Loader:424 - total objects hydrated: 4
13:28:00,912 DEBUG TwoPhaseLoad:79 - resolving associations for [Trade#66936889]
13:28:00,928 DEBUG DefaultLoadEventListener:185 - loading entity: [Account#ABCDE10           ]
13:28:00,928 DEBUG DefaultLoadEventListener:219 - creating new proxy for entity
13:28:00,928 DEBUG TwoPhaseLoad:137 - done materializing entity [Trade#66936889]
13:28:00,944 DEBUG TwoPhaseLoad:79 - resolving associations for [Trade#66936890]
13:28:00,944 DEBUG DefaultLoadEventListener:185 - loading entity: [Account#ABCDE10           ]
13:28:00,944 DEBUG DefaultLoadEventListener:214 - entity proxy found in session cache
13:28:00,944 DEBUG TwoPhaseLoad:137 - done materializing entity [Trade#66936890]
13:28:00,944 DEBUG TwoPhaseLoad:79 - resolving associations for [Trade#67105964]
13:28:00,959 DEBUG DefaultLoadEventListener:185 - loading entity: [Account#ABCDE10           ]
13:28:00,959 DEBUG DefaultLoadEventListener:214 - entity proxy found in session cache
13:28:00,959 DEBUG TwoPhaseLoad:137 - done materializing entity [Trade#67105964]
13:28:00,975 DEBUG TwoPhaseLoad:79 - resolving associations for [Trade#67105965]
13:28:00,975 DEBUG DefaultLoadEventListener:185 - loading entity: [Account#ABCDE10           ]
13:28:00,991 DEBUG DefaultLoadEventListener:214 - entity proxy found in session cache
13:28:00,991 DEBUG TwoPhaseLoad:137 - done materializing entity [Trade#67105965]
13:28:00,991 DEBUG PersistentContext:698 - 2 collections were found in result set
13:28:01,116 DEBUG PersistentContext:727 - collection fully initialized: [trades#ABCDE10           ]
13:28:01,116 DEBUG PersistentContext:727 - collection fully initialized: [trades#ABCDE10]
13:28:01,116 DEBUG PersistentContext:706 - 2 collections initialized
13:28:01,131 DEBUG PersistentContext:656 - initializing non-lazy collections
13:28:01,131 DEBUG DefaultInitializeCollectionEventListener:54 - collection initialized
13:28:01,131 DEBUG Account:92 - getting size of trades from account ! lenght: 0




And here's the code I use to test it :

Code:
public void testAstradeAccountAndTrades(){
   
      SessionFactory sf = new Configuration().configure("db2.cfg.xml").buildSessionFactory();

      Session session = sf.openSession();
      Transaction tx = session.beginTransaction();
      
      Account account = (Account)session.load(Account.class, "ABCDE10");
      logger.debug("account.getAimsAccountProduct()>" + account.getAimsAccountProduct()+"<");
      logger.debug("account.getAimsAccountProductNo()" + account.getAimsAccountProductNo());
      logger.debug("account.getAimsProductCode()" + account.getAimsProductCode());
      
      assertNotNull(account);
   
      assertEquals(account.getAimsAccountProductNo().trim(), "ABCDE10");
      
      int size = account.getTrades().size();
      logger.debug("**************** size 1 : "  + size); // should not be ZERO!!
      Set trades = account.getTrades();
      assertTrue(size!=0); // ERROR HERE!
      Iterator it = trades.iterator();
      while (it.hasNext()){
         Trade trade = (Trade)it.next();
         logger.debug("info trade " + trade.getAimsSecurityNo());
      }
      tx.commit();
      session.close();
      
   }




Any idea?? Thanks for answering.

Etienne
Montreal


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.