| My context: I work in a multi-tenant application with schema based segmentation. I also same entity classes in multiple applications. I would like to define programmatically the schema to be used to locate each table or sequence. The annotations related to schema are :
@Table(schema="myschema" )
@SequenceGenerator(sequenceName = "myschema.seq")
@JoinTable(schema="myschema")
For some annotations, I cannot define the schema statically. I would like Hibernate to use a strategy interface with this simple contract : Contract for internal Hibernate Code:
public void setCurrentProcessingClass(XClass xClass);
public String resolveSchemaName(String annotationSchemaName, String annotationTableName);
public String resolveSequenceName(String annotationSequenceName)
I made call to this methods in two classes :
- org.hibernate.cfg.AnnotationBinder (4 lines added)
- org.hibernate.boot.internal.IdGeneratorInterpreterImpl (1 line added)
Then I delegate to my application class with a simple interface. Contract provided by my application:
String getSchema(Class<?> clazz)
Additional information I can extract from Hibernate calls:
public String getSchemaForTable(String tableName)
public String getSchemaForSequence(String sequenceName)
With this I can implement a SchemaFilterProvider with a SchemaFilter delegating on this implementation : Hibernate org.hibernate.tool.schema.spi.SchemaFilter official contract
boolean includeTable(Table table);
boolean includeSequence(Sequence sequence);
Otherwise, the filter could provide schema name for update but I think this approach would be very complex taking into account the existing code... If I send you the code, could it be considered to be integrated for a future release ? Thanks, Benoit. |