views:

10

answers:

0

Hi there,

I have a class Folder and a class File with a one-to-many relationship between them, implemented with a Map.

Here is the hibernate mapping file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
<hibernate-mapping default-access="field" package="test04">
  <class name="Folder" table="folders">
    <id column="ID" name="id">
      <generator class="native"/>
    </id>
    <property column="HOSTNAME" length="64" name="hostName" type="string"
            unique="true"/>
    <map cascade="all-delete-orphan" lazy="extra" name="pages">
      <key column="FOLDER_ID" not-null="true"/>
      <map-key column="NAME" length="16" type="string"/>
      <one-to-many class="File"/>
    </map>
  </class>
  <class name="File" table="files">
    <id column="ID" name="id">
      <generator class="native"/>
    </id>
    <property name="text" type="text"/>
  </class>
</hibernate-mapping>

The schema that is generated by SchemaExport is as follows (with mysql dialect btw):

alter table files 
    drop 
    foreign key FK5CEBA77B59C31F2;

drop table if exists files;

drop table if exists folders;

create table files (
    ID integer not null auto_increment,
    text longtext,
    FOLDER_ID integer not null,
    NAME varchar(16),
    primary key (ID)
);

create table folders (
    ID integer not null auto_increment,
    HOSTNAME varchar(64) unique,
    primary key (ID)
);

alter table files 
    add index FK5CEBA77B59C31F2 (FOLDER_ID), 
    add constraint FK5CEBA77B59C31F2 
    foreign key (FOLDER_ID) 
    references folders (ID);

What bothers me is that, As I have a Map, I was expecting to have an index on files(FOLDER_ID,NAME), but instead, the index is on FOLDER_ID only.

So I would like to understand the reason for this, and I would like to know if there is a way to get SchemaExport do generate the index I was expecting.

Thanks in advance