-->
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: Undocumented null-padding of lists?
PostPosted: Wed Aug 15, 2007 6:28 pm 
Newbie

Joined: Fri Jan 14, 2005 8:30 pm
Posts: 11
Hibernate version:
Hibernate 3.2.3

Mapping documents:
This is a fragment of themapping file for our Module class...

Code:
   <list name="questions" inverse="true">
       <cache usage="read-only"/>
        <key>
            <column name="module"/>
        </key>
        <index >
            <column name="questionNumber" />
        </index>
        <one-to-many class="abhto.abhc.core.Question" />
    </list>


---

Note that the above mapping uses the column "questionNumber" as the index and does not specify a "base" (resulting in its default of zero).

If we insert records for this collection behind-the-scenes (using JDBC for example) and use non-zero questionNumber value, Hibernate will pad the list with an appropriate number of null entries (before the new entry) when the list is retrieved.

For example, if I insert a *single* question record (for a given module) with a questionNumber of 3, then givenModule.getQuestions.size() is 4 (3 null entries and the newly inserted entry).


It took me awhile to figure out that this was the intended behavior. I guess I had just assumed that I'd see an error or at least a logged warning in the case of non-sequential or non-zero index values in my source data. Instead Hibernate seems to happily and silently pad the list where necessary.

Makes sense and it's kind of a cool feature (although It would still be nice to see a warning of some sort in the logs that my source data for the list requires null-padding).

I reviewed the docs and the FAQS and see no mention of this feature.

Might I suggest we doc this? Sure would have saved me some time this afternoon to have this in the docs or the faq.

(Or maybe someone can just point me to where it's already doc'd if I've blindly missed it).

I'm happy to add this to the documentation myself (if this is allowed), just point me in the right direction.

Thanks!

- Gary


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.