Hibernate has org.hibernate.cfg.Configuration , which is the point at which packets are scanned and configuration files are read.
It uses org.hibernate.cfg.AnnotationBinder.bindClass(...) , which reads class annotations.
These classes (8 kLOC) and methods are so long that I cannot read them easily, so I have no hope for a subclass of Configuration ...
Given that all classes and initialization code that are tied to specific classes without the ability to enter their own, it seems that my task cannot be easily solved using the current Hibernate 4.x architecture.
I start looking for alternatives and ask about externalization of the configuration in the EBean mail list and I got the answer :
public class MySchemaNamingConvention extends com.avaje.ebean.config.UnderscoreNamingConvention { @Override protected TableName getTableNameFromAnnotation(Class<?> beanClass) { final Table t = findTableAnnotation(beanClass); if (t != null && !isEmpty(t.name())) { String catalog = t.catalog(); String schema = t.schema();
So simple that I say goodbye to Hibernate!
UPDATE @Xstian. Before switching to Ebean, I set the default schema via hibernate.default_schema and made extensive use of view and synonym to control which table would be available (Oracle):
grant select on ANOTHER_SCHEMA.TBL to MY_SCHEMA; create or replace view MY_SCHEMA.TBL as select * from ANOTHER_SCHEMA.TBL; create or replace synonym MY_SCHEMA.TBL for ANOTHER_SCHEMA.TBL;
During the transition to views / synonyms, I only have a problem with DB constraints.
If you use the Oracle-FK constraint on the view, do not work unless you add a constraint with the disable novalidate and the same as that specified in PK:
alter view MY_SCHEMA.XXX add constraint PK_XXX primary key(ID) disable novalidate; alter table/view MY_SCHEMA.TBL add constraint FK_XXX foreign key (XXX_ID) references MY_SCHEMA.XXX (ID) disable novalidate;
And synonyms do not allow limiting FK for Oracle at all!
Hibernate seems to dictate the data structure, and I think switching to a more flexible structure is Ebean, but I also evaluate sql2o and jOOQ .