Hi
This post was first posted in the Tools forum but after suggestion from max on the Hibernate Team I've reposted it here (would have moved it if I could). Any moderator, feel free to remove the post in the Tools forum.
The class FoodListMeal has a List of FoodListItem objects. To keep them ordered I'm using <index column="position"/>.
Normally a user has a couple of FoodListItems in a FoodListMeal, i.e. the food_list_item table contains a couple of rows for a particular FoodListMeal.
Now I discovered a user that has two rows where the first row has the value 0 in the position column and the second row has the value 2. The value 1 is missing.
The user originally had three rows with the positions: 0, 1 and 2. Now the middle row is gone and only the two rows with positions 0 and 2 are left.
When the List of FoodListItems is loaded in FoodListMeal, the List gets loaded with two FoodListItem objects and one null object.
foodListItems = [FoodListITem, null, FoodListItem].
I don't know why the user is suddenly lacking a row in the table but is there a way to make Hibernate not load the missing row? Because the null reference later leeds to a NullPointerException.
Hibernate version: 3.1.3
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.mypackage.FoodListMeal" table="food_list_meal">
    
        <id name="id"
            column="food_list_meal_id"
            type="int"
            unsaved-value="-1">
            <generator class="native"></generator>
        </id>
        <version name="version" column="version" type="int"/>
        <property name="mealCategoryId"
           type="java.lang.String"
            update="true" 
            insert="true" 
            column="mealCategoryId"/>
        <list name="foodListItems" 
           lazy="true" 
           inverse="true"
            cascade="all-delete-orphan" 
            batch-size="28">
            <key column="food_list_meal_id"></key>
            <index column="position"/>
            <one-to-many class="com.mypackage.FoodListItem"/>
        </list>
        <many-to-one name="parent"
           class="com.mypackage.FoodListDay"
            cascade="save-update" 
            outer-join="auto" 
            update="true" 
            insert="true"
            column="food_list_day_id" 
            not-null="true"/>
    </class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
Name and version of the database you are using:
MySQL 5