Search code examples
hibernateormeclipselink

Index on foreign key (one-to-many, many-to-one) using orm.xml


Is it possible to use index on foreign key mapping? I have the following orm and after the database generation i see only the index name="index_start", the index on the foreign key are not generated

    <entity name="person" class="gp.model.Person">
            <attributes>
                <basic name="name">
                </basic>
                <one-to-many name="contracts">
                  <join-column name="person_id">
                     <index name="index_person_id" />
                  </join-column>
                </one-to-many>
              <many-to-one name="group">
                  <join-column name="group_id">
                     <index name="index_group_id" />
                  </join-column>
              </many-to-one>
            </attributes>
    </entity>
    <entity name="contract" class="gp.model.Contract">
            <attributes>
                <basic name="start">
                    <index name="index_start"></index>
                    <column name="start_"></column> 
                </basic>
            </attributes>
    </entity>
   <entity name="group" class="gp.model.Group">
            <attributes>

            </attributes>
    </entity>

I tried other option: putting the @index outside the @entity but also it doesn't work. The eclipselink documentation doesn't describe the @index very well.

<index name="index_person_id" table="contracts">
   <column>person_id</column>
<index/>

Solution

  • I solve the problem by adding this property to the persistence-unit file

    <property name="eclipselink.ddl-generation.index-foreign-keys" value="true"/>