-->
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.  [ 3 posts ] 
Author Message
 Post subject: Collections returned padded with large amounts of 'nulls'
PostPosted: Mon Jan 12, 2004 6:39 am 
Newbie

Joined: Tue Jan 06, 2004 5:57 am
Posts: 3
A mapping that involves objects with member collections (mapped as a many-to-one List) works well apart from the fact that the resultant List contains a lot of padding with null references. Is this normal? Do I have to trim these Lists at the time the objects are hydrated or is it a config issue (as I suspect!)

The other unsavoury alternative is to change all code that uses these lists to check for null during iteration - in the current JDBC implementation, nulls would never be added to the list so users of the code don't normally need to check. The biggest problem here would actually be the Velocity templates that access these lists.

The debug output from the net.sf.hibernate hierarchy shows SQL generation that is fine - it returns the correct data if pasted into a database operating shell.

Here's a partial config from the hibernate mapping file:

Code:
    <!--
     - httpsource groups
   -->
   <class name="HttpSourceGroup" table="groups" where="group_type='sources'">
      <id name="id" column="id" type="string" unsaved-value="">
         <generator class="assigned"/>
      </id>
      <property name="title" column="title"/>
      <property name="groupType" column="group_type"/>
      <list name="members" table="sources_groups">
         <key column="group_id"/>
         <index column="id" type="long"/>
         <many-to-many class="HttpSource" column="source_id"/>
      </list>
   </class>
   
   <!--
     - sources
   -->
   <class name="HttpSource" table="sources">
      <id name="id" column="id" type="long" unsaved-value="-1">
         <generator class="identity"/>
      </id>
      <property name="name" column="name"/>
      <property name="url" column="url"/>
      <many-to-one name="transformerType" class="TransformerType" column="transformer_id"/>
   </class>



Following is log output from a section where some 'HttpSourceGroup' objects are hydrated and the resultant SQL with final List population for 'members'. The SQL correctly returns the 2 member rows that are required by this example and further (omitted) logging shows those 2 objects being hydrated.


Code:
[12/01/04 09:36:40:023 GMT] 6fb2a9ce SystemOut     U 2004-01-12 09:36:40,023 DEBUG [net.sf.hibernate.impl.SessionImpl] - <resolving
associations for [com.myco.model.HttpSourceGroup#internal]>

[12/01/04 09:36:40:023 GMT] 6fb2a9ce SystemOut     U 2004-01-12 09:36:40,023 DEBUG [net.sf.hibernate.impl.SessionImpl] - <collection
not cached>

[12/01/04 09:36:40:023 GMT] 6fb2a9ce SystemOut     U 2004-01-12 09:36:40,023 DEBUG [net.sf.hibernate.impl.SessionImpl] - <initializi
ng collection [com.myco.model.HttpSourceGroup.members#internal]>

[12/01/04 09:36:40:023 GMT] 6fb2a9ce SystemOut     U 2004-01-12 09:36:40,023 DEBUG [net.sf.hibernate.impl.BatcherImpl] - <about to o
pen: 1 open PreparedStatements, 1 open ResultSets>

[12/01/04 09:36:40:023 GMT] 6fb2a9ce SystemOut     U 2004-01-12 09:36:40,023 DEBUG [net.sf.hibernate.SQL] - <select members0_.source
_id as source_id__, members0_.group_id as group_id__, members0_.id as id__, httpsource1_.id as id0_, httpsource1_.name as name0_, ht
tpsource1_.url as url0_, httpsource1_.transformer_id as transfor4_0_, transforme2_.id as id1_, transforme2_.name as name1_ from sour
ces_groups members0_ inner join sources httpsource1_ on members0_.source_id=httpsource1_.id left outer join transformers transforme2
_ on httpsource1_.transformer_id=transforme2_.id where members0_.group_id=?>

[12/01/04 09:36:40:023 GMT] 6fb2a9ce SystemOut     U 2004-01-12 09:36:40,023 DEBUG [net.sf.hibernate.impl.BatcherImpl] - <preparing
statement>

[12/01/04 09:36:40:023 GMT] 6fb2a9ce SystemOut     U 2004-01-12 09:36:40,023 DEBUG [net.sf.hibernate.type.StringType] - <binding 'in
ternal' to parameter: 1>



(the above SQL returns the correct 2 members for the group with id 'internal')

Code:
[12/01/04 09:36:40:055 GMT] 6fb2a9ce SystemOut     U 2004-01-12 09:36:40,055 DEBUG [net.sf.hibernate.loader.Loader] - <result set co
ntains (possibly empty) collection: [com.myco.model.HttpSourceGroup.members#internal]>

[12/01/04 09:36:40:055 GMT] 6fb2a9ce SystemOut     U 2004-01-12 09:36:40,055 DEBUG [net.sf.hibernate.impl.SessionImpl] - <uninitiali
zed collection: initializing>


(logs then correctly show the 2 member objects being hydrated)

Code:
[12/01/04 09:36:41:008 GMT] 6fb2a9ce SystemOut     U 2004-01-12 09:36:41,008 DEBUG [net.sf.hibernate.impl.Printer] - <com.myco.model.HttpSourceGroup{groupType=sources, members=[null, HttpSource#1, null, null, HttpSource#9], title=The Title, id=in
ternal}>


The last line of logging (above) highlights the null padded list of member objects. No logging output ever shows a null reference being added to the members collection so I'm guessing it's the result of some sort of internal data conversion (to/from an array?). Is there anything further I need do to prevent it happening?

Regards,
Darren.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 8:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is surely the data in your index column - if you have two rows in your table with indexes 1 and 4, you will get exactly this result.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 8:39 am 
Newbie

Joined: Tue Jan 06, 2004 5:57 am
Posts: 3
of course. Thanks!

I misconfigured the <index> element for <list> and used the database table index column.

Regards,
Darren


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.