I have a Practice object that holds a java.util.Map. The key column of the Map is a TypeSafe Enum implementation. The value is a java.util.List containing OpeningHour objects. The weekday number (int) should end up in the day column.
I supplied the classes and the schema of the openinghours-table.
I'm new to Hibernate and this is a hard one to solve for me. All help and suggestions welcome!
Code:
public class Practice implements java.io.Serializable {
private Long id;
private String name;
// Contains a WeekDay as the key and a List of OpeningHours
private Map weekdays = new HashMap(7);
...
}
Code:
public class WeekDay implements Serializable {
public static final WeekDay MONDAY = new WeekDay(Calendar.MONDAY, "Monday");
public static final WeekDay TUESDAY = new WeekDay(Calendar.TUESDAY, "Tuesday");
...
}
Code:
public class OpeningHours implements Serializable {
private long id;
private Time openAt;
private Time closedAt;
...
}
Code:
public class Time implements Serializable{
private int hours;
private int minutes;
...
}
Code:
<hibernate-mapping>
<class name="com.physioware.vo.OpeningHours" table="openinghours">
<id name="id" column="id" unsaved-value="null">
<generator class="increment"/>
</id>
<component name="openAt" class="com.physioware.vo.Time">
<property name="hours" column="starthh" not-null="true"/>
<property name="minutes" column="startmm" not-null="true"/>
</component>
<component name="closedAt" class="com.physioware.vo.Time">
<property name="hours" column="endhh" not-null="true"/>
<property name="minutes" column="endmm" not-null="true"/>
</component>
</class>
</hibernate-mapping>
Code:
CREATE TABLE openinghours(
id INT UNSIGNED NOT NULL auto_increment,
practice SMALLINT UNSIGNED NOT NULL REFERENCES practice(practiceid),
day TINYINT(1) NOT NULL,
starthh NUMERIC(2) NOT NULL,
startmm NUMERIC(2) NOT NULL,
stophh NUMERIC(2) NOT NULL,
stopmm NUMERIC(2) NOT NULL,
PRIMARY KEY(id)
);
Hibernate version: 2.1.8
Name and version of the database you are using: MySQL 4.0.20a