-->
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: need a List as the many in a 1-*, sorted on Date
PostPosted: Fri Nov 05, 2004 3:27 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 2:54 pm
Posts: 33
Location: Austin, TX
Hibernate supports the List in one-to-many associations, but the index must be an integer. I have the following mapping for medical office patients and the prescriptions they are currently taking:

Code:
<class name="Patient" table="patients">
    <id name="id" column="patient_id" type="long" unsaved-value="null">
      <generator class="hilo"/>
    </id>
    <property name="firstName" type="string"
        length="25" not-null="true"/>
    <property name="lastName" type="string"
        length="25" not-null="true"/>
        <property name="DOB" type="date"/>
    <property name="city" type="string" length="15" not-null="true"/>
    <property name="state" type="string" length="2" not-null="true"/>
    <property name="zip" type="string" length="10" not-null="true"/>
    <set name="Rxs" cascade="all" inverse="true" lazy="false">
      <key column="patient_id"/>
      <one-to-many class="com.txdx.pojo.Rx"/>
    </set>
  </class>


The set above does not work for me because I need the prescriptions to sort on date and be non-unique. Here is my prescription mapping:

Code:
<class name="Rx" table="rxs">
    <id name="id" column="rx_id"
    type="long" unsaved-value="null">   
      <generator class="hilo"/>
    </id>
    <property name="brandName"  type="string" length="35" not-null="true"/>
    <property name="genericName"  type="string" length="35"/>
    <property name="rxDate"  type="date"/>
    <property name="dosage"  type="float"/>
    <property name="instructions"  type="string"/>
    <many-to-one name="patient" class="com.txdx.pojo.Patient" column="patient_id"/>
  </class>


The prescriptions in the collection need to be sorted on rxDate, but a list sorts on an integer type. The id in the prescription table is there as a leftover from the example I started with.

Is there a way to create this one-to-many association where the collection is a List? How would I tell hibernate to convert that date to an integer in the declaration?

_________________
--Pierce Krouse


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 05, 2004 5:41 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
try

Code:
   
    <bag name="Rxs" cascade="all" inverse="true" lazy="false" order-by="rxDate">
      <key column="patient_id"/>
      <one-to-many class="com.txdx.pojo.Rx"/>
    </bag>


HTH
Ernst


Top
 Profile  
 
 Post subject: need a List as the many in a 1-*, sorted on Date
PostPosted: Fri Nov 05, 2004 6:58 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 2:54 pm
Posts: 33
Location: Austin, TX
Thanks for the prompt and complete reply Ernst -- I'll definitely give that one a try.

_________________
--Pierce Krouse


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.