Armin wrote:
I found nothing about null elements in a list and how hibernate maps them. In a test case hibernate just ignores them, so a list with one null element is saved as a null. Or a list with some null values at the end of the list, the size of the list after saving it is smaller than before. Null values with an array are also ignored, so a saved array is smaller in length than it should be. Is there a solution (besides from a accessor which masks null values)?
I digged in the source code and it seems that there is a simple fix for this problem:
in net.sf.hibernate.collection.List use the following entryExists method.
Code:
public boolean entryExists(Object entry, int i) {
if ( entry==null ) {
return i==list.size()-1;
} else {
return true;
}
}
it writes a null value if the last element in the list ist null. So at most on null value is written. The same approach works with ArrayHolder, Bag,...
I don't know if there are side effects or if the current behaviour is wanted. In our project we need a way to load the state of an array/list with null elements and a mask/unmask accessor inhibits a foreign key relation![/list]