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