Hi, I believe I found a minor bug on hibernate, my code changes schemas at runtime by deploying the same jar to different PersistenceUnits, each one having its own different schema, schemas werent being handled properly so I found the following in hibernate code (org.hibernate.cfg.Configuration.java):
Code:
String defaultCatalog = properties.getProperty( Environment.DEFAULT_CATALOG );
String defaultSchema = properties.getProperty( Environment.DEFAULT_SCHEMA );
// ...
TableMetadata tableInfo = databaseMetadata.getTableMetadata(
table.getName(),
//table.getSchema(), <-- this line fails, at least with my DB (Using Postrgres)
defaultSchema, // <-- So I changed for this one wich changes schema properly
table.getCatalog() // <-- Don't know if catalog should be fetched from environment too
);
// ...
inside functions
Code:
public String[] generateSchemaUpdateScript(Dialect dialect, DatabaseMetadata databaseMetadata) throws HibernateException { ... }
and
public void validateSchema(Dialect dialect, DatabaseMetadata databaseMetadata) throws HibernateException { ... }
Now schemas are handled properly, but changing that lead to another error, IndexOutOfBoundsException (org.hibernate.tool.hbm2ddl.DatabaseMetadata.java) :
Code:
public boolean isTable(Object key) throws HibernateException {
if(key instanceof String) {
if ( getTableMetadata( (String) key, null, null ) != null ) {
return true;
} else {
String[] strings = StringHelper.split(".", (String) key);
if(strings.length==3) {
return getTableMetadata(strings[2], strings[1], strings[2]) != null;
} else if (strings.length==2) {
// This is the code I changed, IndexOutOfBounds was here
return getTableMetadata(strings[1], strings[0], null) != null;
// This was the original code
// return getTableMetadata(strings[2], strings[1], null) != null;
}
}
}
return false;
}
now beans compile and deploy succesfully, and persistence units are changed to others on different schemas at runtime, DDL are created propery and (so far) everything works fine (apparently).
If this is really a bug, don't who to tell, nor how.
----------------------------------------
jBoss 4.0.3SP1
Hibernate 3.1.2 (Compiled with custom fixes)
PostgreSQL 8
Debian/XeonDual