I have a DB that has 2 schemas. The schemas are “structurally equivalent” and guaranteed to stay that way. One of the schemas is considered the "staging" schema and the other is considered the "master" schema. By “structurally equivalent” I mean each schema has the same number of tables with the same names, the same column names, the same constraints, etc …
When data enters the system it gets placed in the "staging" schema. Once the data is considered finalized, and deemed acceptable, it is moved to the "master" schema.
I realize it's an unusual architecture, but unfortunately I have to live with it.
I am in the process of designing the code that will access these schemas. I want to write one set of java code that will access both schemas. At runtime the correct schema will be accessed based on the user type.
My approach will be to create 2 Session Factories - one for each schema. At runtime I can decide which Session Factory to use based on the user type.
I envision code like the following:
Code:
If (adminUser) {
hSession = HibernateUtil.getMasterSession();
} else {
hSession = HibernateUtil.getStagingSession();
}
MyClass myClass = (MyClass) hSession.get(MyClass.class, new Long(myClassId));
[ ... rest of code here ...]
In order for this to work I need to use one POJO (MyClass) with both Session Factories.
Can this be done? If so, how?