-->
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.  [ 1 post ] 
Author Message
 Post subject: hibernate and c3p0 get raw jdbc conncetion problem
PostPosted: Thu Apr 19, 2012 5:52 am 
Newbie

Joined: Tue Apr 17, 2012 5:58 am
Posts: 5
hi all,

I am using c3p0 as a connection pool provider in my j2se application and every thing is ok. For some reason I want to run java.sql.connection.isValid(int); before running a query. I get the connection in this way
Code:
Session sess = em.unwrap(Session.class);
         sess.doWork(
                new Work() {
                    public void execute(Connection connection) throws SQLException
                    {
                       connection.isValid(20);
                                        }
                                    });


em is my entity manager, I have the following exception in connection.isValid(20);
Code:
Exception in thread "Thread-10" java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyConnection.isValid(I)Z
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)
   at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
   at $Proxy20.isValid(Unknown Source)
   at com.edafa.lba.dao.CycleDAO$1.execute(CycleDAO.java:79)
   at org.hibernate.jdbc.WorkExecutor.executeWork(WorkExecutor.java:54)
   at org.hibernate.internal.SessionImpl$1.accept(SessionImpl.java:1850)
   at org.hibernate.internal.SessionImpl$1.accept(SessionImpl.java:1847)
   at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork(JdbcCoordinatorImpl.java:211)
   at org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:1868)
   at org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:1854)
   at com.edafa.lba.dao.CycleDAO.getAllActiveCyclesInThisMoment(CycleDAO.java:75)
   at com.edafa.lba.modules.LBAExecuter.execute(LBAExecuter.java:74)
   at com.edafa.lba.main.LBAMain$2.run(LBAMain.java:56)



when I try to cast the connection to C3P0ProxyConnection to invoke the method using java reflection api like this
Code:
Session sess = em.unwrap(Session.class);
         sess.doWork(new Work() {
            public void execute(Connection connection) throws SQLException {

               try {

                  C3P0ProxyConnection c3p0Connection = (C3P0ProxyConnection) connection;

                  Method m = Connection.class.getMethod("isValid",
                        int.class);
                  Object[] args = new Object[] { new Integer(10) };
                  Boolean result = (Boolean) c3p0Connection
                        .rawConnectionOperation(m,
                              C3P0ProxyConnection.RAW_CONNECTION,
                              args);

                  System.err.println(result);
               } catch (Exception exex) {
                  exex.printStackTrace();
               }
            }
         });


I get the following exception
Code:
java.lang.ClassCastException: $Proxy20 cannot be cast to com.mchange.v2.c3p0.C3P0ProxyConnection
   at com.edafa.lba.dao.CycleDAO$1.execute(CycleDAO.java:84)
   at org.hibernate.jdbc.WorkExecutor.executeWork(WorkExecutor.java:54)
   at org.hibernate.internal.SessionImpl$1.accept(SessionImpl.java:1850)
   at org.hibernate.internal.SessionImpl$1.accept(SessionImpl.java:1847)
   at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork(JdbcCoordinatorImpl.java:211)
   at org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:1868)
   at org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:1854)
   at com.edafa.lba.dao.CycleDAO.getAllActiveCyclesInThisMoment(CycleDAO.java:75)
   at com.edafa.lba.modules.LBAExecuter.execute(LBAExecuter.java:74)
   at com.edafa.lba.main.LBAMain$2.run(LBAMain.java:56)


any help please?

thnx in advance:)

shady,


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

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.