-->
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.  [ 1 post ] 
Author Message
 Post subject: How to map an ordered collection ?
PostPosted: Mon Dec 20, 2010 7:16 pm 
Pro
Pro

Joined: Mon Apr 16, 2007 8:10 am
Posts: 246
I have an ordered collection property, containing items with a given ordered stored in a listOrder property.

I wonder how to code the Hibernate mapping so as to have the collection of items, ordered by their listOrder property.

Here is the current mapping:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 18, 2010 1:03:51 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="com.thalasoft.learnintouch.core.domain.FormItem" table="form_item" dynamic-insert="true" dynamic-update="true">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="identity" />
        </id>
        <version name="version" type="int">
            <column name="version" not-null="true" />
        </version>
        <many-to-one name="mailList" class="com.thalasoft.learnintouch.core.domain.MailList" fetch="select">
            <column name="mail_list_id" />
        </many-to-one>
        <many-to-one name="form" class="com.thalasoft.learnintouch.core.domain.Form" fetch="join">
            <column name="form_id" not-null="true" />
        </many-to-one>
        <property name="type" type="string">
            <column name="type" length="50" not-null="true" />
        </property>
        <property name="name" type="string">
            <column name="name" length="50" />
        </property>
        <property name="text" type="text">
            <column name="text" length="65535" />
        </property>
        <property name="help" type="string">
            <column name="help" />
        </property>
        <property name="defaultValue" type="string">
            <column name="default_value" length="50" />
        </property>
        <property name="size" type="string">
            <column name="size" length="3" />
        </property>
        <property name="maxlength" type="string">
            <column name="maxlength" length="4" />
        </property>
        <property name="listOrder" type="int">
            <column name="list_order" not-null="true" />
        </property>
        <property name="inMailAddress" type="boolean">
            <column name="in_mail_address" />
        </property>
    </class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 18, 2010 1:03:51 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="com.thalasoft.learnintouch.core.domain.Form" table="form" dynamic-insert="true" dynamic-update="true">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="identity" />
        </id>
        <version name="version" type="int">
            <column name="version" not-null="true" />
        </version>
        <property name="name" type="string">
            <column name="name" length="50" not-null="true" />
        </property>
        <property name="description" type="string">
            <column name="description" />
        </property>
        <property name="title" type="string">
            <column name="title" />
        </property>
        <property name="image" type="string">
            <column name="image" length="50" />
        </property>
        <property name="email" type="string">
            <column name="email" />
        </property>
        <property name="instructions" type="text">
            <column name="instructions" length="65535" />
        </property>
        <property name="acknowledge" type="text">
            <column name="acknowledge" length="65535" />
        </property>
        <property name="webpage" type="string">
            <column name="webpage_id" />
        </property>
        <property name="mailSubject" type="string">
            <column name="mail_subject" />
        </property>
        <property name="mailMessage" type="text">
            <column name="mail_message" length="65535" />
        </property>
        <set name="formItems" inverse="true" cascade="all-delete-orphan" order-by="list_order">
            <key>
                <column name="form_id" not-null="true" />
            </key>
            <one-to-many class="com.thalasoft.learnintouch.core.domain.FormItem" />
        </set>
    </class>
</hibernate-mapping>


My wish is to have the collection with the items in the same order as the rows retrieved by Hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.