Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is Connection.setSchema() (JDBC4) supported? #9

Closed
edysli opened this issue May 21, 2013 · 6 comments
Closed

Is Connection.setSchema() (JDBC4) supported? #9

edysli opened this issue May 21, 2013 · 6 comments

Comments

@edysli
Copy link

edysli commented May 21, 2013

Hi,
I've tried using Connection.setSchema() in my code but got an AbstractMethodError exception:

java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyConnection.setSchema(Ljava/lang/String;)V

This occurs with version 0.9.5-pre2 and 0.9.5-pre3-SNAPSHOT.
So is Connection.setSchema() supposed to be supported?

@swaldman
Copy link
Owner

hi,

setSchema() is supported by 0.9.5-pre3-SNAPSHOT. If you are seeing an AbstractMethodError in 0.9.5-pre3-SNAPSHOT, it is likely because your driver fails to support the method. The error you report above was, I'd be willing to bet, generated under 0.9.2.x or a previous version. Here's a very similar error, generated under 0.9.5-pre3-SNAPSHOT against postgresql-8.2-504.jdbc3.jar:

java.lang.AbstractMethodError: org.postgresql.jdbc3.Jdbc3Connection.setSchema(Ljava/lang/String;)V

Note the distinction -- under 0.9.5-pre3, the abstract method error still occurs but in the JDBC driver's Connection object rather than in com.mchange.v2.c3p0.impl.NewProxyConnection. With a more recent postgres driver, postgresql-9.2-1002.jdbc4.jar, the error is only slightly more informative:

java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc4.Jdbc4Connection.setSchema(String) is not yet implemented.

Please recheck under 0.9.5-pre3-SNAPSHOT. Verify that the build you are running is indeed a 0.9.5-pre3-SNAPSHOT [look in your logs for a line like "Initializing c3p0-0.9.5-pre3"], and inspect the error message carefully. Are you sure the AbstractMethodError you see is coming from com.mchange.v2.c3p0.impl.NewProxyConnection rather than a JDBC driver class?

c3p0-0.9.5-pre3 should support all JDK 1.7 / JDBC 4 methods now, but only if the underlying driver also supports them.

@edysli
Copy link
Author

edysli commented May 22, 2013

I ran a new build of my project and I confirm it uses 0.9.5-pre3-SNAPSHOT. Here are the log lines from c3p0's startup:

5022 [MLog-Init-Reporter] INFO  com.mchange.v2.log.MLog - MLog clients using log4j logging.
5371 [main] INFO  com.mchange.v2.c3p0.C3P0Registry - Initializing c3p0-0.9.5-pre3 [built 19-May-2013 07:22:27 -0700; debug? true; trace: 10]

I'm using HSQL 2.2.9 and, if I read it's javadoc correctly (http://hsqldb.org/doc/2.0/apidocs/org/hsqldb/jdbc/JDBCConnection.html), it should implement setSchema. The first line of the error is still:

java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyConnection.setSchema(Ljava/lang/String;)V

This project also uses Hibernate (4.2) and Spring Framework (3.2) so maybe some other dependency is causing the problem... If it helps, I can try to create a small project with the same dependencies to reproduce the error.

Below is the full stack trace of one such error:

java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyConnection.setSchema(Ljava/lang/String;)V
    at my code (DAO)
    at org.hibernate.jdbc.WorkExecutor.executeWork(WorkExecutor.java:54)
    at org.hibernate.internal.SessionImpl$2.accept(SessionImpl.java:1981)
    at org.hibernate.internal.SessionImpl$2.accept(SessionImpl.java:1978)
    at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork(JdbcCoordinatorImpl.java:284)
    at org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:1999)
    at org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:1985)
    at my code (DAO)
    at my code (DAO)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy34.myMethod(Unknown Source)
    at my code (service)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.aop.interceptor.PerformanceMonitorInterceptor.invokeUnderTrace(PerformanceMonitorInterceptor.java:62)
    at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:111)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy38.myMethod(Unknown Source)
    at my code (controller)
    at my code (integration test)

@swaldman
Copy link
Owner

hi,

if you can send a small demonstration, that would be fantastic.

setSchema( ... ) really is in the generated code for NewProxyConnection, and when i call the method, it clearly does get through the c3p0 layer (only to fail at my underlying driver ). so this is very puzzling.

@edysli
Copy link
Author

edysli commented May 22, 2013

I managed to make a demonstration project for this error. It is available here https://github.com/edysli/c3p0_AbstractMethodError_demo. Run mvn test (on Java 7) and the exception should appear.

Looks like you already fixed it though; I accidentally ran Maven with --update-snapshots, it downloaded a new snapshot and I got a different exception. :) I can still trigger the AbstractMethodError with 0.9.5-pre2.

@swaldman
Copy link
Owner

Wow. You are right. A quick javap confirms that c3p0-0.9.5-pre2's NewProxyConnection includes only JDBC3 methods, while c3p0-0.9.5-pre1 and c3p0-0.9.5-pre3-SNAPSHOT properly includes all JDK1.7 methods. I'm not sure how this happened; I must have had an JDBC library somehow shadow JDBC4 libs when I built, although that should be hard since c3p0-0.9.5-preX won't build in anything but 1.7. This build quirk may remain a mystery, but I'll go ahead and make c3p0-0.9.5-pre3 a release to cover up the shame and embarrassment. :) And I'll be sure to test for the presence of JDBC4 methods going forward.

Thank you for the demo project. I had to edit the aspectj.version property to 1.7.2 rather than 1.7.2-RELEASE, but other than that it worked fine. (Of course I played around with c3p0 versions.) Except for in -pre2, the error I'm now getting is org.hibernate.exception.SQLGrammarException inside hsqldb libs.

@edysli
Copy link
Author

edysli commented May 23, 2013

Thank you for fixing it! :)

@ewsq ewsq mentioned this issue Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants