We have a requirment for partitioning data for certain clients via horizontal database partitioning - in other words we do not mix data in a table amongst clients so it is partitioned. How Oracle figures out which partition you need to query against is with a generic id (for our POC we call it Bank ID as shown in the code below).
The issue that we have is that we need to set a context on the actual Connection that Hibernate is going to use - as shown in the code below. The context essentially talks to a Policy Enforcement Point and gets the WHERE predicate for use (e.g. where bank id like so-and-so) this would get appended to the original sql query sent by Hibernate to Oracle and oracle VPD could then direct to the proper partition.
However this is a bit of a pain - as the goal is to make this as transaparent as possible, so we thought we could use an interceptor to force the setting of this context. However we have not identified any way of getting a handle on the session via an interceptor - is there a way?
Perhaps there is an easier way of accomplishing this setting of the context outside of interceptors?
Thanks in advance.
Hibernate version:
3.2.2 GA
Mapping documents:
Mapping problem not the issue - rather an architectural type of issues
Full stack trace of any exception that occurs:
none
Name and version of the database you are using:
Oracle 10g
Code between sessionFactory.openSession() and session.close():
Code:
SessionFactory factory = new Configuration().configure().buildSessionFactory();
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
// get handle to Connection from hibernate session
Connection myConnection = session.connection();
try
{
// *** set security context - username
CallableStatement cs1 = myConnection.prepareCall("{call secpck.setsecctx(?,?)}");
cs1.setString(1, "jdoe");
cs1.setString(2, "test=test");
cs1.execute();
// execute hibernate query
Criteria crit = session.createCriteria(Partition.class);
List<Partition> partitions = crit.setMaxResults(10).list();
tx.commit();
for (Partition p : partitions)
{
System.out.println("ID:" + p.getId() + " Bank ID:" + p.getBankId() + " Timestamp:"
+ p.getTimestamp().getTimeInMillis());
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
session.close();
factory.close();
[/code]