I'm using hibernate 2.1.3 against an Oracle 8i db.
I need to change the schema qualifier for ALL tables and sequences used by hibernate at runtime. All my hibernate.cfg.xml has placeholder value for "default_schema" and none of my mapping files explicitly define the schema (via the schema attribute on the <hibernate-mapping> tag).
I've seen similar postings on this (namely
http://forum.hibernate.org/viewtopic.ph ... ass+schema).
In that post, you mention that it's ok to change change the schema name for each PersistentClass (via the Configuration object). The default_schema setting seemed to take care of the tables, but my sequence generators weren't including the schema. I tried 2 different ways of setting the schema for my sequences:
Code:
hibernateConfig.setProperty( "hibernate.default_schema", schemaName ) ;
// method 1
pc.getTable().setSchema( schemaName ) ;
// method 2
hibernateConfiguration.getClassMapping( SomeClass.class ).getIdentifier().getIdentifierGeneratorProperties().setProperty(
"sequence", schemaName + ".MY_DB_SEQ" ) ;
Didn't work. So, I linked up the hibernate 2.1.3 source in eclipse and stepped through. Here's the culprit (SimpleValue.createIdentifierGenerator( Dialect ): 81:
Code:
public IdentifierGenerator createIdentifierGenerator(Dialect dialect) throws MappingException {
if (uniqueIdentifierGenerator==null) {
uniqueIdentifierGenerator = IdentifierGeneratorFactory.create(
identifierGeneratorStrategy, type, identifierGeneratorProperties, dialect
);
}
return uniqueIdentifierGenerator;
}
When I initially loaded my Configuration from the mapping files on disk, it apparently set up and cached the uniqueIdenfierGenerator (without my schema name prepended to the sequence!!) When I change the SimpleValue using the code above and re-created a new SessionFactory, the cached uniqueIdentifierGenerator remains and my changes are ignored.
Any way this can be fixed? I supposed I can inject the schema attribute into every xml mapping file at runtime using DOM, but that seems like a hack when you guys put together such a nice Configuration interface =(