-->
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.  [ 33 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Thu Oct 22, 2009 9:36 am 
Newbie

Joined: Thu Feb 05, 2009 3:37 pm
Posts: 13
You need to ad a property in order to tell hibernate to use your custom connection provider
<!-- <property name="hibernate.connection.provider_class"
value="yourpackage.hibernate.ProxyAuthenticationConnectionProviderImpl"/>
-->
Be aware of the type of framework you are(ejb, spring,etc) in order to know what connectionprovider to extend


cheers

Julian


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Fri Oct 23, 2009 6:17 am 
Newbie

Joined: Thu Oct 22, 2009 7:07 am
Posts: 10
Thanks, Julian!
Your last post helped me a lot!

Now I see - right connections that where made with proxy.
But something gone wrong with connection pool. It perfectly returns connections to the application sevral times, but then stoppes and does not answer. Untill I restart tomcat with my application. What can it be?

Thre greater number of hibernate.c3p0.max_size I have, the longer application works.

Here is my config:

Code:
<property name="connection.url">jdbc:oracle:thin:@161.8.200.251:1521:DBG9</property>
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="connection.username">PROXY</property>
    <property name="connection.password">PROXY</property>
    <property name="hibernate.c3p0.acquire_increment">5</property>
    <property name="hibernate.c3p0.max_size">20</property>
    <property name="hibernate.c3p0.min_size">10</property>
    <property name="hibernate.c3p0.idle_test_period">300</property>
    <property name="hibernate.c3p0.max_statements">3</property>
   
    <!--<property name="hibernate.c3p0.timeout">10</property>-->
    <property name="connection.provider_class">budget.proxy.AppConnectionProvider</property>
    <!--<property name="connection.pool_size">1</property>-->
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="show_sql">false</property>
    <property name="dialect">org.hibernate.dialect.OracleDialect</property>


Thanks in advance


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Fri Oct 23, 2009 8:14 am 
Newbie

Joined: Thu Feb 05, 2009 3:37 pm
Posts: 13
Try to add some debug code in order to see if the connections are returning to the pool, it seems they are not. And check your oracle database when tomcat stops responding for open sessions(there you will have the idea on whats happening) you may do
Code:
select * from v$session
logged in as system. You should check there two things. 1 if hibernate is closing open session (check if you have open connections with particular username) and then check if you are returning the connections to the pool, proxy user.

Cheers


Julian


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Fri Oct 23, 2009 11:08 pm 
Newbie

Joined: Thu Oct 22, 2009 7:07 am
Posts: 10
Here is my code, which using connections
Code:
public List getBudgets(Date dateBeg, Date dateEnd) {
        List budgets = new ArrayList<Budget>();
        Session session =null;
        try {
            session = HibernateUtil.getSessionFactory().openSession();
            Criteria crit = session.createCriteria(Budget.class).add(Restrictions.between("period",dateBeg, dateEnd));
            budgets.addAll(crit.list());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
        return budgets;
    }

Calling this function several times stops pool.

As I can understand session.close(); method must return connection to pool?
Every time function executes - the number of recordset of the statement select * from v$session decrements by 1. When this recordset becomes empty the pool stops.

What is wrong in my function? session = HibernateUtil.getSessionFactory().openSession();?
When I used this code without pooling it worked all right!
Thanks


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Mon Oct 26, 2009 8:08 am 
Newbie

Joined: Thu Oct 22, 2009 7:07 am
Posts: 10
Here is my ConnectionProvider

Code:
package budget.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import oracle.jdbc.driver.OracleConnection;
import org.hibernate.connection.C3P0ConnectionProvider;
import org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.security.userdetails.User;


/**
*
* @author Chumansky
*/
public class AppConnectionProvider extends C3P0ConnectionProvider {

    @Override
    public Connection getConnection() throws SQLException {
       User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
       System.out.println("..та.с. откр.т. сое..нен.е ...: "+user.getUsername());
       if (user != null) {
           return setUserForConnection(super.getConnection(),user.getUsername());
       } else {
           return super.getConnection();
       }
    }

    @Override
    public void closeConnection(Connection conn) throws SQLException {
        this.closeProxyConnection(conn);
        super.closeConnection(conn);
    }
    private Connection setUserForConnection(Connection pConn, String userName) throws SQLException {
        try {
            C3P0NativeJdbcExtractor cp30NativeJdbcExtractor = new C3P0NativeJdbcExtractor();
            OracleConnection conn = (OracleConnection) cp30NativeJdbcExtractor.getNativeConnection(pConn);
            Properties prop = new Properties();
            prop.setProperty(OracleConnection.PROXY_USER_NAME, userName);
            conn.openProxySession(OracleConnection.PROXYTYPE_USER_NAME, prop);
            return conn;
        } catch (SQLException e) {
            e.printStackTrace(System.err);
            throw e;
        }
    }
    private void closeProxyConnection(Connection pConn) {
       
       try {
           //OracleConnection conn = (OracleConnection)pConn;
           C3P0NativeJdbcExtractor cp30NativeJdbcExtractor = new C3P0NativeJdbcExtractor();
           OracleConnection conn = (OracleConnection) cp30NativeJdbcExtractor.getNativeConnection(pConn);
           if (conn.isProxySession()) {
               conn.close(OracleConnection.PROXY_SESSION);

           }
       } catch (Exception e) {
           e.printStackTrace();
       }
   }
}


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Mon Oct 26, 2009 8:42 am 
Newbie

Joined: Thu Oct 22, 2009 7:07 am
Posts: 10
I only had to extract OracleConnection with C3P0NativeJdbcExtractor
In my case it cannot be cast as shown in Julian sample:

Code:
OracleConnection conn = (OracleConnection)pConn;

So I do:
Code:
OracleConnection conn = (OracleConnection) cp30NativeJdbcExtractor.getNativeConnection(pConn);

It works, but still the connections do not return back to pool after they are closed

What can I do to make connections to return back to pool???


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Mon Oct 26, 2009 9:04 am 
Newbie

Joined: Thu Feb 05, 2009 3:37 pm
Posts: 13
Try to add some debug code in order to see if the proxy sessions are actually been closed. You should execute the query to the v$session view in order to see the name of the users been connected, try to doit outside your app, if you can, paste the result of the v$session when it is working, and when the pool stops


cheers


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Mon Oct 26, 2009 9:37 am 
Newbie

Joined: Thu Oct 22, 2009 7:07 am
Posts: 10
Debuging messages

Code:
@Override
    public void closeConnection(Connection conn) throws SQLException {

        C3P0NativeJdbcExtractor cp30NativeJdbcExtractor = new C3P0NativeJdbcExtractor();
        OracleConnection oconn = (OracleConnection) cp30NativeJdbcExtractor.getNativeConnection(conn);
        System.out.println("Before closing: hibernate session is closed?:"+conn.isClosed());
        System.out.println("Before closing: Oracle session is closed? is proxy?: "+oconn.isClosed()+" / "+oconn.isProxySession());
        if (oconn.isProxySession()) {
               oconn.close(OracleConnection.PROXY_SESSION);
               oconn.close(OracleConnection.INVALID_CONNECTION);
           }
        System.out.println("After closing: Oracle session is closed? is proxy?: "+oconn.isClosed()+" / "+oconn.isProxySession());
        System.out.println("After closing: hibernate session is closed?:"+conn.isClosed());
        super.closeConnection(conn);
        System.out.println("After closing once more time: hibernate session is closed?::"+conn.isClosed());
    }


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Mon Oct 26, 2009 9:38 am 
Newbie

Joined: Thu Oct 22, 2009 7:07 am
Posts: 10
Code:
<property name="connection.url">jdbc:oracle:thin:@161.8.200.251:1521:DBG9</property>
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="connection.username">PROXY</property>
    <property name="connection.password">PROXY</property>
    <property name="hibernate.c3p0.acquire_increment">5</property>
    <property name="hibernate.c3p0.max_size">10</property>
    <property name="hibernate.c3p0.min_size">5</property>
    <property name="hibernate.c3p0.idle_test_period">300</property>
    <property name="hibernate.c3p0.max_statements">3</property>
    <!--<property name="hibernate.c3p0.timeout">10</property>-->
    <property name="connection.provider_class">budget.proxy.AppConnectionProvider1</property>


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Mon Oct 26, 2009 9:40 am 
Newbie

Joined: Thu Feb 05, 2009 3:37 pm
Posts: 13
Please post the outout of the debuggin messages, and the results of the query to de v$session when the app works, and when the pool stops

cheers


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Mon Oct 26, 2009 9:45 am 
Newbie

Joined: Thu Oct 22, 2009 7:07 am
Posts: 10
Before closing: hibernate session is closed?:false
Before closing: Oracle session is closed? is proxy?: false / true
After closing: Oracle session is closed? is proxy?: true / false
After closing: hibernate session is closed?:true
After closing once more time: hibernate session is closed?::true


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Mon Oct 26, 2009 9:50 am 
Newbie

Joined: Thu Oct 22, 2009 7:07 am
Posts: 10
The result of
select * from v$session
where machine = 'ASchumansky'

Three rows for user PROXY

When I make query one more time the number of rows decreases
I understand - the number of queries I can do is equals the parameter
Code:
<property name="hibernate.c3p0.max_size">10</property>


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Mon Oct 26, 2009 10:00 am 
Newbie

Joined: Thu Feb 05, 2009 3:37 pm
Posts: 13
As far as i can see the proxy session are actually closing. The problem does not seems to be proxy connections, but the connectin pooling.


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Mon Oct 26, 2009 10:15 am 
Newbie

Joined: Thu Oct 22, 2009 7:07 am
Posts: 10
May be the jars versions are not suitable?
I sent you my project. If only you have time to look at newbies code I'll be pleased to know your opinion on the subject. Otherwise don't care

Thanks


Top
 Profile  
 
 Post subject: Re: Using Oracle Proxy Authentication
PostPosted: Mon Oct 26, 2009 10:22 am 
Newbie

Joined: Thu Feb 05, 2009 3:37 pm
Posts: 13
Yes, send it, not problem. How many tables are you using? If they are not that much you can send me the script to create the tables also

Cheers

Julian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 33 posts ]  Go to page Previous  1, 2, 3  Next

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.