I have the following two mappings:
Code:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.activemath.xlm.model">
<class name="LearnerModel" table="LModel">
<cache usage="read-write" />
<id name="id" type="long" access="field">
<generator class="native" />
</id>
<natural-id>
<property name="learnerId"/>
</natural-id>
<map name="beliefs" access="field" lazy="true" cascade="all-delete-orphan">
<cache usage="read-write" />
<key column="lModelId" /> <
<composite-map-key class="BeliefDescriptor">
<key-property name="metacogId" access="field" />
<key-property name="motivationId" access="field" />
<key-property name="affectId" access="field" />
<key-property name="competencyId" access="field" />
<key-property name="capeId" access="field" />
<key-property name="domainId" access="field" />
</composite-map-key>
<one-to-many class="Belief"/>
</map>
</class>
</hibernate-mapping>
and
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 default-access="field"
package="org.activemath.xlm.model">
<class name="Belief" table="Belief" >
<cache usage="read-write" />
<id type="long">
<generator class="native" />
</id>
<property name="news" />
<property name="unresolved" />
<component class="MassDistribution" name="massDist">
<primitive-array name="massDist" table="MassDist">
<key column="Belief_id"/>
<list-index column="lSetOrd"/>
<element column="bpa" type="double" />
</primitive-array>
</component>
<list lazy="true" access="field" name="evidence" cascade="all,delete-orphan">
<cache usage="read-write" />
<key column="Belief_id" not-null="true"/>
<list-index column="n" />
<one-to-many class="Evidence"/>
</list>
</class>
</hibernate-mapping>
They generate the following DDL:
Code:
create table LModel (id bigint not null,
learnerId varchar(255) not null,
primary key (id),
unique (learnerId))
create table Belief (id bigint not null,
news integer,
unresolved integer,
lModelId bigint,
metacogId varchar(255),
motivationId varchar(255),
affectId varchar(255),
competencyId varchar(255),
capeId varchar(255),
domainId varchar(255),
primary key (id))
alter table Belief add constraint FK7661CDC1DB3FBD00 foreign key (lModelId) references LModel
Now, my guess is that, being (lModelId, metacogId,..., domainId) not null, it would be useful if a (unique) index would be created for them in the database. I thought of declaring it as a natural-id in the mapping for Belief, but a Belief does not refer to its Model nor BeliefDescriptor in my Java code . So my question is about how to tell Hibernate that (lModelId, metacogId,..., domainId) is a suitable candidate for a (unique) index.
Any ideas?