-->
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.  [ 1 post ] 
Author Message
 Post subject: SchemaUpdate and automatic index creation...
PostPosted: Thu Sep 02, 2004 4:24 pm 
Newbie

Joined: Thu Mar 04, 2004 3:13 pm
Posts: 2
Hibernate version: 2.1.6
Name and version of the database you are using: MySQL 4.1.1a - alpha

I am using hibernate with a pre-existing database (not created by hibernate), and need to create indices on several tables if they don't already exist. The application will be used with many databases (the output of another application, not under our control), so it would be very nice if we could automatically create the necessary index definitions. I have been having some difficulty using SchemaUpdate to accomplish this task, a quick look at the source revealed the problem.

In net.sf.hibernate.cfg.Configuration:

Code:
public String[] generateSchemaUpdateScript(Dialect dialect, DatabaseMetadata databaseMetadata) throws HibernateException {
.
.
.
         /*//broken, 'cos we don't generate these with names in SchemaExport
         subIter = table.getIndexIterator();
         while ( subIter.hasNext() ) {
            Index index = (Index) subIter.next();
            if ( !index.isForeignKey() || !dialect.hasImplicitIndexForForeignKey() ) {
               if ( tableInfo==null || tableInfo.getIndexMetadata( index.getName() ) == null ) {
                  script.add( index.sqlCreateString(dialect, mapping) );
               }
            }
         }
         //broken, 'cos we don't generate these with names in SchemaExport
         //broken, 'cos we don't generate these with names in SchemaExport
         subIter = table.getUniqueKeyIterator();
         while ( subIter.hasNext() ) {
            UniqueKey uk = (UniqueKey) subIter.next();
            if ( tableInfo==null || tableInfo.getIndexMetadata( uk.getName() ) == null ) {
               script.add( uk.sqlCreateString(dialect, mapping) );
            }
         }*/
.
.
.


The lines that appear to generate the index are commented out...
Uncommenting a portion of the first section:

Code:
subIter = table.getIndexIterator();
         while ( subIter.hasNext() ) {
            Index index = (Index) subIter.next();
//            if ( !index.isForeignKey() || !dialect.hasImplicitIndexForForeignKey() ) {
               if ( tableInfo==null || tableInfo.getIndexMetadata( index.getName() ) == null ) {
                  script.add( index.sqlCreateString(dialect, mapping) );
               }
//            }
         }


Seems to work perfectly with my application and database configuration, generating only missing indices, and not creating duplicates (as I've seen mentioned in other posts). I am just curious as to why these lines were removed (especially if they are in fact broken somehow), and if there is a possibility that this functionality will be restored in SchemaUpdate at some point.

Thank You
Dan


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

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.