On 25 Nov 2003, at 13:44, Hugo Burm wrote:

Hi Hugo, thanks for your help.

What are you using for the Hibernate mapping? A Set or a List?

A java.util.List.

I think you nee a List and set the <index> attribute (ch 5.2 of the
Hibernate ref manual) to the index of your Woody ArrayList.

Albums are mapped like this (they use 'posn' as the index) :

<class name="uk.co.my.bean.Album" table="albums">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<property name="title" type="string" length="128" not-null="true"/>
<property name="text" type="string" length="1024" not-null="true"/>
<property name="publishable" type="boolean" not-null="true"/>
<property name="modified" type="timestamp"/>
<many-to-one name="user" class="uk.co.my.bean.User" column="userid" not-null="true"/>
<list name="resources" table="resources" cascade="all" lazy="true">
<key column="albumid"/>
<index column="posn"/>
<one-to-many class="uk.co.my.bean.Resource"/>
</list>
</class>

The Resource mapping looks like this :

<class name="uk.co.my.bean.Resource" table="resources">
        <id name="id" column="id" type="long">
                <generator class="native"/>
        </id>
        <property name="text" type="string" length="1024" not-null="true"/>
        <property name="reference" type="string" length="512" not-null="true"/>
</class>

This jUnit tests successfully re-arrange the Resources :

// re-arrange test
((Resource)resources.get (0)).setText ("blah");
Resource temp = (Resource)resources.get (1);
resources.set (1, resources.get (0));
resources.set (0, temp);
AlbumPeer.save(SESSION, album);
SESSION.refresh (album);
assertTrue ("Resources not re-arranged", ((Resource)album.getResources ().get (1)).getText ().equals ("blah"));

This is basically a copy of how Woody does it.
When this runs, I see the 'posn' being updated by Hibernate.

However, when you call form.save (album); and then persist the Album, the reverse-binding has not effected the positioning of the Persisted Resources.

Hibernate is not updating 'posn' when the Albums is persisted after the re-arrangement, when that re-arrangement has been done by Woody.

I guess one of the problems will be sorting after you added a new item,
because the new item does not yet have an id in Woody.

I have not got that far yet ;)

regards Jeremy

Hugo Burm


-----Original Message-----
From: Jeremy Quinn [mailto:[EMAIL PROTECTED]
Sent: 25 November 2003 13:47
To: [EMAIL PROTECTED]
Subject: persisting re-arranged repeater-rows


Hi All,

I am struggling with persisting re-arranged repeater rows.

I have a form that edits an Album Bean which has a (java.util.List)
'Resources' Property which is populated by Resource Beans.

I have the List of Resource Beans represented in the form as a
repeater-widget, with move-up, move-down buttons.

When I click one of the up/down buttons, the repeater-rows get
re-arranged correctly in the form.

When I save the Album (I am using Hibernate, with cascading)
the change
in the ordering is not persisted.

I am clearly missing something ..... has anyone else had with
a similar
issue?

Any suggestions?

Thanks for any help

regards Jeremy


Attachment: smime.p7s
Description: S/MIME cryptographic signature



Reply via email to