How to Connect to Oracle VPD using Hibernate

Oracle VPD or Virtual Private Database is a Oracle Database feature that provides data access control features for the database. You cannot directly access the VPD data using the persistence managers like Hibernate or JPA. There's an option of using Oracle Toplink, but it is not a free for commercial use. The following "work-around" allows you to use Oracle VPD with Hibernate API.

You need to create an implementation of the ConnectionProvider which will override the default connection provider. package org.javazone.hibernate; import org.hibernate.connection.DriverManagerConnectionProvider; public class MyConnectionProvider extends DriverManagerConnectionProvider { @Override /** * Execute the VPD specific Stored Procedure. */ public Connection getConnection() throws SQLException { Connection conn = super.getConnection(); //Put your VPD specific logic here. return conn; } } Next step is to make sure that MyConnectionProvider is used by hibernate. You can edit the hibernate.cfg.xml as shown below: org.javazone.hibernate.MyConnectionProvider

This property will make the Hibernate invoke the MyConnectionProvider whenever a new connection is requested by the application.

Comments

Need some help

Doug, We could really use some help related to this subject. Are you able to provide some more info where JNDI is used and how can you be reached directly ? Thanks

Give out some example

Hi Duke, I am new to hibernate as well as to oracle vpd, i just gone thru one site "http://www.adp-gmbh.ch/ora/security/vpd/index.html" for oracle vpd functionality, from database level, In the example what they have given is like connect Peter/Peter, my question is just checking out the username an password will make a connection or should we explicitly specify some connection statement. Could u give us some sample example application "source code" using hibernate and oracle vpd. Or any website or any tutorial or any document explaining about this to implement oracle vpd functionality through java applications.

Post new comment

The content of this field is kept private and will not be shown publicly.