-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping a complex Map
PostPosted: Fri May 06, 2005 12:32 pm 
Newbie

Joined: Fri May 06, 2005 12:13 pm
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.