-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Automatically submitting commands on a new connection
PostPosted: Thu Mar 15, 2007 8:27 pm 
Newbie

Joined: Thu Mar 15, 2007 8:10 pm
Posts: 1
Hi,
I want to automatically submit two commands on each newly created connection to my DB but I cannot work out how to do this with Hibernate. I was hoping there would be an interceptor or event that would allow me access to the new connection just after it has been created, but I've been unable to find such a thing. Extending the dialect class is also a possibility but it does not appear to have anything relating to connection initialisation either.

The two commands are to make Oracle 10g case-insensitive and ought to be submitted when the connection is first obtained from Oracle. They are:

alter session set nls_comp=linguistic
alter session set nls_sort=binary_ci

Pointers to the best (transparent) approach using Hibernate would be most appreciated.

Cheers,
Paul

P.S. Using a database trigger like the following would seem like a good idea, however the Oracle Thin JDBC driver sets nls_language to your default locale on each new connection. This has the side effect of setting nls_sort back to 'binary':

create or replace trigger on_connect after logon on database
begin
execute immediate 'alter session set nls_comp=linguistic';
execute immediate 'alter session set nls_sort=binary_ci';
end;


Top
 Profile  
 
 Post subject: not working
PostPosted: Wed Aug 06, 2008 4:38 am 
Newbie

Joined: Wed Aug 06, 2008 4:33 am
Posts: 1
Location: Pune
I tried this but it is not giving expected results. Its working fine from plsql prompt.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 07, 2008 1:45 pm 
Newbie

Joined: Mon Aug 15, 2005 2:00 pm
Posts: 19
Subclass the org.hibernate.connection.DatasourceConnectionProvider, override the getConnection() method, and place your commands there:

Code:
   @Override
   public Connection getConnection() throws SQLException {
      Connection conn = super.getConnection();
      // do whatever stuff you need with this connection
      return conn;
   }


Then declare your class as the connection provider in hibernate.properties (or whatever you use to configure Hibernate):

hibernate.connection.provider_class=your.class.goes.here

HTH,

Alex


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.