-->
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.  [ 12 posts ] 
Author Message
 Post subject: POSITION field in <list> collection mapping not filled
PostPosted: Mon May 09, 2005 11:30 am 
Beginner
Beginner

Joined: Fri Mar 11, 2005 7:52 am
Posts: 34
Hello,

I want to use the <list> collection mapping instead of the <set> (to preserve ordering). Thefore I specify:

Code:
  <class name="WeekSchedule" table="WEEK_SCHEDULE">

    <id name="Id" type="int" column="ID">
      <generator class="native"/>
    </id>

    <list name="DaySchedules" inverse="true" cascade="all-delete-orphan">
      <key column="WEEK_SCHEDULE_ID"/>
      <index column="POSITION"/>
      <one-to-many class="DaySchedule"/>
    </list>

  </class>


The POSITION field in DaySchedule is created but not filled... Do I have to specify more than just the index column?

regards,

Roland Beuker


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 2:08 pm 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
I can't (quickly) locate the FAQ/Article/Wiki, but I found somewhere on the site where in Hibernate 2.x list indexes are not assigned automatically and you have to do something clever in your getter like this:

Code:
public class DaySchedule
{
   // Fields
   private int position = -1;

   // Some getters/setters

   public void setPosition( int aPosition )
   {
      this.position = aPosition;
   }

   public int getPosition( )
   {
       int newPosition = this.position;
       if( this.getWeekSchedule( ) != null )
       {
          newPosition = this.getWeekSchedule( )
             .getDaySchedules( )
             .indexOf( this );
       }
       return newPosition;
   }

   // More getters/setters

   // Constructors, methods, etc.
}


When Hibernate goes to persist the list, it will determine the indexes dynamically.

- Jesse


Top
 Profile  
 
 Post subject: Is this still true for hibernate-3.0
PostPosted: Mon May 09, 2005 2:26 pm 
Beginner
Beginner

Joined: Fri Mar 11, 2005 7:52 am
Posts: 34
Hello Jesse,

Is this still true for hibernate-3.0

Thanks,

Roland


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 5:50 pm 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
I think (and I am by no means certain) that I saw a post somewhere by one of the authors/admins indicating that there was a solution for this in Hibernate3, but I don't know what it is.

- Jesse


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 5:12 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read the documentation, there are several examples of list mappings in Hibernate 3.0.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 5:29 am 
Beginner
Beginner

Joined: Fri Mar 11, 2005 7:52 am
Posts: 34
christian wrote:
Read the documentation, there are several examples of list mappings in Hibernate 3.0.


Hello Christian,

I studied both the “Bible of Hibernate” ;-) and the reference documentation… But I cannot find how to generate the list indexes. The POSITION fields are created but not filled…

I have the following configuration:

Code:
<class name="WeekSchedule" table="WEEK_SCHEDULE">
    <id name="Id" type="int" column="ID">
      <generator class="native"/>
    </id>
    <list name="DaySchedules" inverse="true" cascade="all-delete-orphan">
      <key column="DAY_SCHEDULE_ID"/>
      <index column="POSITION"/>
      <one-to-many class="DaySchedule"/>
    </list>
  </class>

<class name="DaySchedule" table="DAY_SCHEDULE">
    <id name="Id" type="int" column="ID">
      <generator class="native"/>
    </id>
    <many-to-one
      name="weekSchedule"
      column="WEEK_SCHEDULE_ID"
      class="WeekSchedule"
      not-null="true"/>
    <set name="Periods" inverse="true" cascade="all-delete-orphan">
      <key column="DAY_SCHEDULE_ID"/>
      <one-to-many class="Period"/>
    </set>
</class>


Is the solution from Jesse also true for hibernate-3.0 of is there a more clear approach?

Regards,

Roland Beuker


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 7:43 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Look at one of the unit tests if you want to copy paste code from a working example.


Top
 Profile  
 
 Post subject: still no position information
PostPosted: Wed May 11, 2005 8:54 am 
Beginner
Beginner

Joined: Fri Mar 11, 2005 7:52 am
Posts: 34
christian wrote:
Look at one of the unit tests if you want to copy paste code from a working example.


Just like the Customer/Order classes from the unit test I suplied a getter/setter for the index in DaySchedule (in the unit test example is this getOrderNumber/setOrderNumber in the Order class) but still the position field in my case is not filled %$*^%^(&$*&


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 12:21 pm 
Newbie

Joined: Tue Sep 26, 2006 8:34 am
Posts: 16
Location: Paris, France
@christian could you point an online hibernate3 test mapping list with list-index that shows up reordering?

i was not able to find something that match my requirements which are

Hibernate 3.2 mapping one-to-many with list using list-index and show how to reorder the list


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 4:16 pm 
Newbie

Joined: Sun Dec 17, 2006 6:39 pm
Posts: 8
Hi,

I'm having a similar problem. Please see my post:

http://forum.hibernate.org/viewtopic.php?t=968743

Sorry, no solution so far :-(


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 4:50 am 
Beginner
Beginner

Joined: Fri Mar 11, 2005 7:52 am
Posts: 34
adam77 wrote:
Hi,

I'm having a similar problem. Please see my post:

http://forum.hibernate.org/viewtopic.php?t=968743

Sorry, no solution so far :-(


I have a solution. For a list with index you need a key for this index:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"./etc/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.eye.hibernate">

<class name="DaySchedule" table="DAY_SCHEDULE">

<cache usage="read-write"/>

<composite-id>
<key-many-to-one name="weekSchedule" column="WEEK_SCHEDULE_ID" class="WeekSchedule"/>
<key-property name="DayOfWeek" column="DAY_OF_WEEK"/>
</composite-id>

<version name="version" column="VERSION" unsaved-value="undefined"/>

<property name="DayScheduleName" column="DAY_SCHEDULE_NAME"/>

<list name="Periods" inverse="true" cascade="all-delete-orphan">
<key>
<column name="WEEK_SCHEDULE_ID"/>
<column name="DAY_OF_WEEK"/>
</key>
<index column="PERIOD_ID"/>
<one-to-many class="Period"/>
</list>

<property name="Active" column="ACTIVE"/>

</class>

</hibernate-mapping>

****************************************************

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"./etc/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.eye.hibernate">

<class name="WeekSchedule" table="WEEK_SCHEDULE">

<cache usage="read-write"/>

<id name="Id" type="int" column="ID">
<generator class="native"/>
</id>

<list name="DaySchedules" inverse="true" cascade="all-delete-orphan" lazy="true">
<cache usage="read-write"/>
<key column="WEEK_SCHEDULE_ID"/>
<index column="DAY_OF_WEEK"/>
<one-to-many class="DaySchedule"/>
</list>

<property name="WeekScheduleID" column="WEEK_SCHEDULE_ID"/>
<property name="WeekScheduleName" column="WEEK_SCHEDULE_NAME"/>

<property name="Active" column="ACTIVE"/>

<set name="WeekScheduleInFpus" inverse="true" cascade="all-delete-orphan" lazy="true">
<cache usage="read-write"/>
<key column="WEEK_SCHEDULE_ID"/>
<one-to-many class="WeekScheduleInFpu"/>
</set>

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 12:26 pm 
Newbie

Joined: Tue Sep 26, 2006 8:34 am
Posts: 16
Location: Paris, France
i finally solve my issue which look similar to your's

check http://forum.hibernate.org/viewtopic.php?t=968296


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.