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