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?