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,