I have studied hibernate using this wonderful book. Of course, it does not cover all cases.
I'm trying to put Hibernate in some practice developing a small software for managing skydive dropzones.
I'm having a question mapping a component class inside another class. Let me explain.
I have a class named Aircraft with two String fields (licence and description) and its getters and setters. I have another simple class named AircraftJumpPrice, with two numeric fields (altitude and price).
I want to make an aggregation mapping with this two classes, like this:
Code:
<class name="br.com.noground.entities.Aircraft">
<id name="id">
<generator class="increment"/>
</id>
<property name="prefix" length="5" not-null="true"/>
<property name="description" length="50" not-null="true"/>
<set name="jumpPrices" lazy="true">
<key column="aircraft"/>
<composite-element class="br.com.noground.entities.AircraftJumpPrice">
<property name="altitude" not-null="true"/>
<property name="amount" not-null="true"/>
</composite-element>
</set>
</class>
That is, one aircraft have a set of jump prices, one for each altitude.
My question is: how do I make the property to be unique but only inside a Set? Just like the way I showed above, duplicate jump prices with the same altitude can repeat for the same aircraft. For example:
for the aircraft "NPLEE (Twin Otter)" I have the following prices:
at 13000ft the price is $ 20
at 7000ft the price is $ 10
for the aircraft "NHJSA (Cessna Caravan)" I have the following prices:
at 13000ft the price is $ 19
at 7000ft the price is $ 10
I cannot have the unique constraint to the property "altitude" it wont allow the 13000ft again for the NHJSA aircraft.
Any ideas?