Hibernate – Oracle : Creating Index For Foreign-Key Columns

In Oracle adding Index for Foreign Key columns is  important for performance reasons.  And also if you are using transactions,  It is important to create index for FK columns.  With out  index your application may experience many deadlock problems.

These indexes are automatically generated for MySQL by Hibernate (In MySQL Index for FK columns is mandatory).  But these indices are  not generated for Oracle by Hibernate.

So we need to  explicitly mention indexes in hibernate mapping tables.

For hibernate  <list> </list>   objects we can use <database-object> tag for explicitly mention the create/drop index.

<hibernate-mapping>
……
……
<database-object>
    <create>CREATE INDEX  ACCOUNT_IDX ON Person(ACCOUNTID)</create>
    <drop>DROP INDEX ACCOUNT_IDX ON Person</drop>
    <dialect-scope name=”org.hibernate.dialect.Oracle10gDialect”></dialect-scope>
</database-object>
<hibernate-mapping>

 

Advertisements
This entry was posted in Hibernate, java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s