Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Hib3] Accessing the Connection first

 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to use Oracle Auditing to track user operations, but to get it working with the OR layer and the connection pool, I need to access to Connection and run a script to identify the user on the session before the DB operations take place. (LInks below)

Specifically I need to run EXECUTE DBMS_SESSION.SET_IDENTIFIER ('SCOTT'), I don't actually need access to the Connection as long as I can ensure that the query gets executed on the connection first.

Ta,
Dave

http://www.oracle.com/technology/oramag/webcolumns/2003/techarticles/nanda_fga.html
http://www.oracle.com/technology/pub/articles/nanda_fga_pt2.html
http://www.oracle.com/technology/pub/articles/nanda_fga_pt3.html
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to complicate things, we're using Spring and not vanilla Hibernate, so I'll need something that allows us to perform thread-safe operations against Hibernate.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Short version of how I did it:
extend ...hibernate3.HibernateTransactionManager
Override doBegin() to something like this:

super.doBegin();
Session session = //get session from the util thingy now that the transaction and session are defined in the line above
Connection conn = Session.getConnection();
//do my own specific stuff on the Connection
Note: do not close the Connection!

We implemented an Http Filter to capture requests and place the current user on a ThreadLocal, then the code above pulls the user and writes it to the client_id on the (Oracle) connection. Seems to work just fine.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops, I should say I overrode the Spring HibernateTransactionManager. It makes all the difference
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic