-->
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: Problem using <index column
PostPosted: Wed Aug 15, 2007 9:58 am 
Newbie

Joined: Wed Aug 15, 2007 9:20 am
Posts: 5
Hi

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 16, 2007 4:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
sounds like you should be posting in the user forum not the tools forum.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 16, 2007 4:49 am 
Newbie

Joined: Wed Aug 15, 2007 9:20 am
Posts: 5
max wrote:
sounds like you should be posting in the user forum not the tools forum.


Thanks, I've created a identical post in the user forum (I would have moved it if I could). Please, feel free to remove this thread if you like.

// Mattias


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.