Hibernate provides the index attribute to let you define additional indexes on columns. However, it does not allow you to add an index to a column where the column is a key.
The essence of the schema is this: A one-to-many list association, where the parent contains a list of children:
Code:
<class name="ParentClass" table="PARENT_TABLE">
<list name="childrenList" table="PARENT_CHILD_LIST" cascade="all" inverse="false" access="MyAccessor">
<key column="PARENT_ID"/>
<list-index column="CHILD_LIST_POSITION"/>
<element column="CHILD_ID" type="long"/>
</list>
</class>
The PK for the association table is PARENT_ID + LIST_POSITION, as it should be.
There is no index generated on the PARENT_ID. Since hibernate handles its collection associations by "delete all followed by insert all", the delete where PARENT_ID equals <givenID> must do a full table scan. No good.
So I need hibernate to create an index on PARENT_ID.
The problem is that the standard index attribute for creating additional indices may not be attached to the key element.
IOW, <key column="PARENT_ID" index="myParentFKIndex"/> is not allowed.
I can't find a way around this using the schema definition alone. Anyone got a workaround? TIA