Hibernate version: 3
I have a question regarding hibernate mappings and composite keys. I have 3 java classes whose data members I have shown below. A service is a static table with a number of provisioned services. Each subscriber has a servicelist which is a one to many relationship. The primary key (PK) for each table is indicated for each class. I am wondering what is the best way to define the hibernate mapping for the CopyService class ? At the moment I am using a composite key but this is discouraged as described in the book Hibernate In Action. Not sure what’s the best alternative ?
Service:
private Long serviceid;
PK
private String name;
private String description;
private Boolean systemStatus;
Subscriber:
private Long subscriberid;
PK
private String msisdn;
private String password;
private String emailaddress;
private Set servicelist;
CopyService:
private Long copyserviceid;
PK
private Long subscriberid;
PK
private Set emaillist;
private Set msisdnlist;
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="dbase">
<class name=" Subscriber"
table="Subscriber">
<id name="subscriberid" column="subscriberid" type="long" unsaved-value="null">
<generator class="native" />
</id>
<property name="msisdn" column="msisdn" type="java.lang.String"
not-null="true" unique="true" />
<property name="password" column="password"
type="java.lang.String" not-null="true" />
<property name="email" column="email" type="java.lang.String" />
<set name="servicelist" table="Subscriber_Servicelist">
<key column="subscriberid" />
<many-to-many class="Service" column="serviceid" unique="true"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping package="dbase">
<class name="CopyService" table="copy-service">
<composite-id name="id" class="CopyServiceKey">
<key-property name="id" column="id" type="java.lang.Long"/>
<key-property name="subscriberid" column="subscriberid" type="java.lang.Long"/>
</composite-id>
<property name="email" column="email" type="java.lang.String" />
<property name="msisdn" column="msisdn" type="java.lang.String" />
</class>
</hibernate-mapping>