-->
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: how to index a composite-map-key
PostPosted: Wed Apr 04, 2007 6:28 pm 
Newbie

Joined: Fri Oct 14, 2005 8:37 am
Posts: 10
Location: University of Edinburgh
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?


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