I am developing my first Hibernate application, which will be used to manage stores for a grocery chain.
The Store object owns a collection of items, called ExtraordinaryTimetable, representing extraordinary opening and closing hours on special days (e.g. holydays). The timetable objects are subject to a workflow, so they have a "status" property.
I first modeled this association with a Set in the Store class, and made the timetable object an entity for Hibernate. Then I changed my mind, and decided that it made more sense to map them as a component of Store. The idea is to have a Map of timetable items in the Store object, using the date as a key.
Here are some snippets of my java sources and mappings:
public class Store {
...
private Map extraordinaryTimetable;
...
}
public class ExtraordinaryTimetable {
...
private Date date;
private Date opening;
private Date closing;
private short status;
...
}
<hibernate-mapping>
<class name="...Store" table="TSTORE">
...
<map name="extraordinaryTimetable" table="TEXTTTB">
<key column="id_store"/>
<index column="DATE" type="date"/>
<composite-element class="...ExtraordinaryTimetable">
<property name="opening" type="time"/>
<property name="closing" type="time"/>
<property name="status"/>
...
</composite-element>
</map>
...
</class>
</hibernate-mapping>
Now, here's the problem and my question.
The workflow allows more than one timetable item to have the same date, if they have a different status (items with the same status must have different dates).
Therefore I need to have separate Map's in the Store class for each status, but at the same time I would like to keep all items in the same database table.
Is there a way to have Hibernate populate my maps using the status column as a discriminator, much like it does when dealing with subclasses?
|