I am trying to build multitenancy based on unique schema for each client
So there would be a single datasource to Oracle in weblogic server
the datasource would have a user which has synonyms / grants to all client schemas
Let us ignore the fact whether this is good or bad or horrible design - I just want to find a way to get it to work
I am defining the datasource as a part of my hibernate.cfg.xml file
The sessionfactory will get created from this hibernate.cfg.xml
From reading on the internet - I will have to add additional properties in my hibernate.cfg.xml
<session-factory>
<property name="connection.datasource">MYSQLDS</property>
<property name="default_schema">testpage</property>
<!-- multitenant properties start here -->
<property name="multi_tenant_connection_provider">multiTenantConnectionProvider</property>
<property name="multiTenancy">SCHEMA</property>
<property name="tenant_identifier_resolver">CurrentTenantIdentifierResolverImpl</property>
&globalpit;
</session-factory>
Now is the part that I dont understand:
It seems for CurrentTenantIdentifierResolverImpl I will implement a custom class that will implement the interface
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
public class SchemaResolver implements CurrentTenantIdentifierResolver {
@Override
public String resolveCurrentTenantIdentifier() {
return "master";
}
@Override
public boolean validateExistingCurrentSessions() {
return false;
}
}
So I am quite confused how this class and its methods will get invoked - I do understand that this is used to determine which schema is to be used based on some identifier unique to a client - ala user http session ?
The next part is the implementation of MultiTenantConnectionProvider and again its methods such as
public Connection getConnection(String tenantIdentifier) throws SQLException {
RANT -START This strangely starts looking like good old plain and simple JDBC :) so am wondering why I have to use hibernate :( RANT-END
So related to this method and the class - how do I consume it ?
The frustrating part is lots of places where you get to see these two classes defined - but no explanation of how these are invoked ?
Is there a complete end to end example of how to use these two classes with a clear example of how these two classes are consumed - not just the two stand alone classes please !