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.  [ 2 posts ] 
Author Message
 Post subject: Adding indexes to key columns
PostPosted: Sun Sep 10, 2006 12:50 pm 
Beginner
Beginner

Joined: Sat Oct 29, 2005 2:05 am
Posts: 21
Location: Kansas City, KS
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 10, 2006 4:03 pm 
Beginner
Beginner

Joined: Sat Oct 29, 2005 2:05 am
Posts: 21
Location: Kansas City, KS
Problem solved: It works if you use the correct xml:
Code:
<class name="ParentClass" table="PARENT_TABLE">
   <list name="childrenList"  table="PARENT_CHILD_LIST"  cascade="all" inverse="false" access="MyAccessor">
      <key>
         <column name="PARENT_ID" index="PARENT_CHILD_LIST_FK"/>
      </key>
      <list-index column="CHILD_LIST_POSITION"/>
      <element column="CHILD_ID" type="long"/>
   </list>
</class>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.