简体   繁体   中英

java.lang.AbstractMethodError: at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.setCharacterStream(DelegatingPreparedStatement.java:328)

I have a very pesky problem and i can't seem to find the answer anywhere.

My application throws this exception when trying to persist a @Lob:

java.lang.AbstractMethodError
 at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.setCharacterStream(DelegatingPreparedStatement.java:328)
 at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.setCharacterStream(DelegatingPreparedStatement.java:328)
 at java.lang.reflect.Method.invoke(Method.java:601)
 at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
 at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
 at $Proxy32.setCharacterStream(Unknown Source)
 at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$3$1.doBind(ClobTypeDescriptor.java:83)
 at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92)
 at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280)
 at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:275)
 at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:57)
 at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2747)
 at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3152)
 at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3087)
 at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3416)
 at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:140)
 at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
 at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
 at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:276)
 at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
 at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
 at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1213)
 at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:402)
 at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
 ...(more)

I am running on Tomcat 6.0.36(also tried tomcat 7).

MySQL 4.1.22 database.

Code is compiled with jdk 7 and built with gradle.

My dependencies are:

+--- javax.mail:mail:1.4 -> 1.4.1
|    \--- javax.activation:activation:1.1
+--- org.slf4j:slf4j-api:1.5.6 -> 1.6.1
+--- log4j:log4j:1.2.13 -> 1.2.16
+--- org.apache.wicket:wicket:1.4.15
|    \--- org.slf4j:slf4j-api:1.5.8 -> 1.6.1
+--- org.apache.wicket:wicket-extensions:1.4.15
|    +--- org.apache.wicket:wicket:1.4.15 (*)
|    \--- org.slf4j:slf4j-api:1.5.8 -> 1.6.1
+--- mysql:mysql-connector-java:5.1.26
+--- com.microsoft.sqlserver:sqljdbc4:4.0
+--- com.itextpdf:itextpdf:5.4.2
+--- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final -> 1.0.1.Final
+--- org.hibernate:hibernate-core:4.1.9.Final
|    +--- antlr:antlr:2.7.7
|    +--- org.jboss.logging:jboss-logging:3.1.0.GA
|    +--- org.javassist:javassist:3.17.1-GA
|    +--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:1.0.0.Final
|    +--- dom4j:dom4j:1.6.1
|    |    \--- xml-apis:xml-apis:1.0.b2
|    +--- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final
|    \--- org.hibernate.common:hibernate-commons-annotations:4.0.1.Final
|         \--- org.jboss.logging:jboss-logging:3.1.0.CR2 -> 3.1.0.GA
+--- org.hibernate:hibernate-entitymanager:4.1.9.Final
|    +--- org.jboss.logging:jboss-logging:3.1.0.GA
|    +--- org.javassist:javassist:3.17.1-GA
|    +--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:1.0.0.Final
|    +--- dom4j:dom4j:1.6.1 (*)
|    +--- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final
|    +--- org.hibernate:hibernate-core:4.1.9.Final (*)
|    \--- org.hibernate.common:hibernate-commons-annotations:4.0.1.Final (*)
+--- foo.bar.data-services:foor-bar-data:2.0.0.275
|    +--- org.slf4j:slf4j-api:1.6.1
|    +--- org.hibernate:hibernate-core:4.1.6.Final -> 4.1.9.Final (*)
|    +--- org.hibernate.javax.persistence:hibernate-jpa-2.0-api::1.0.1.Final -> 1.0.1.Final
|    +--- org.slf4j:slf4j-log4j12:1.6.1
|    |    +--- org.slf4j:slf4j-api:1.6.1
|    |    \--- log4j:log4j:1.2.16
|    +--- log4j:log4j:1.2.16
|    \--- commons-configuration:commons-configuration:1.9
|         +--- commons-lang:commons-lang:2.6
|         \--- commons-logging:commons-logging:1.1.1
+--- javax.transaction:jta:1.1
+--- dom4j:dom4j:1.6.1 (*)
+--- antlr:antlr:2.7.6 -> 2.7.7
+--- commons-collections:commons-collections:3.2.1
+--- commons-configuration:commons-configuration:1.9 (*)
+--- commons-dbcp:commons-dbcp:1.4
|    \--- commons-pool:commons-pool:1.5.4 -> 1.5.7
+--- commons-pool:commons-pool:1.5.7
+--- commons-logging:commons-logging:1.1.1
+--- commons-dbutils:commons-dbutils:1.4
+--- commons-lang:commons-lang:2.6
+--- commons-io:commons-io:2.4
+--- org.apache.commons:commons-email:1.2
|    +--- javax.mail:mail:1.4.1 (*)
|    \--- javax.activation:activation:1.1
+--- javax.servlet:servlet-api:2.5
+--- javax.servlet.jsp:jsp-api:2.1
\--- org.slf4j:slf4j-log4j12:1.5.6 -> 1.6.1 (*)

So looking at the exception, it seems like the application is trying to call the tomcat-dbcp.jar in the CATALINA_BASE/lib folder. But i would expect it to call my commons-dbcp.jar in my classpath.

But frankly i'm at a loss, i tried a lot of things, but can't seem to get this working... Thanks in advance for your help. Tell me if you need more information.

EDIT 1:

server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">

    <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
    <Listener className="org.apache.catalina.core.JasperListener"/>
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
    <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

    <GlobalNamingResources>
        <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
        <Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" logAbandoned="true" maxActive="100" maxIdle="10" maxWait="10000" name="jdbc/foo" removeAbandoned="true" removeAbandonedTimeout="300" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/foo?autoReconnect=true&amp;dumpQueriesOnException=true" username="root" validationQuery="select 1"/>     
        <Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" logAbandoned="true" maxActive="20" maxIdle="5" maxWait="10000" name="jdbc/bar" removeAbandoned="true" removeAbandonedTimeout="300" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/bar?autoReconnect=true&amp;dumpQueriesOnException=true" username="root" validationQuery="select 1"/>
    </GlobalNamingResources>

    <Service name="Catalina">
        <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
        <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>

        <Engine defaultHost="localhost" name="Catalina">
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
            <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
            <Context docBase="foo" path="/foo" reloadable="true" source="org.eclipse.jst.j2ee.server:foo"/></Host>
        </Engine>
    </Service>
</Server>

The solution was to use tomcat 7. This has a version of tomcat-dbcp.jar that actually has the DelegatingPreparedStatement.setCharacterStream that the application needed.

My problem was that when i tried it on my tomcat 7 server, i still got the same error at the same place in my application. This was caused by an old version of mysql-connector-java(5.0.5 if i remember correctly) that was lingering in my tomcat lib folder due to earlier attempts to make this work. This older version apparently had precedence over my own mysql-connector-java(newest version) that i have as a dependency. Because this gave me the same exception, it seemed that it did not change anything in my situation, while it actually did.

When i figured this out, the rest was easy, my only problem was that i couldn't upgrade very easily to tomcat 7, since other applications are currently running on our tomcat 6 version in the production environment. So the solution was to copy the tomcat-dbcp.jar from a tomcat 7 dist to our tomcat 6 server and replacing the one that was already there.

Hope this will help others as well, thanks to everyone for all the help in any case!

AbstractMethodError is a subclass of LinkageError, which nearly always indicates that something is wrong with your classpath--libraries that were not compiled together are being loaded together.

Assuming your library versions line up with my momentary research...

The line that's throwing the exception is DelegatingPreparedStatement:328 . It looks like this:

((PreparedStatement)_stmt).setCharacterStream(parameterIndex, reader, length);

If you click through to setCharacterStream , you see it's tagged as @since 1.6 .

So, you should:

  1. Make sure you're running under a 1.6+ VM. :)

  2. Check that there are no other implementations of java.sql.PreparedStatement anywhere in your classpath. The way I usually do this (in a Unix-like system; you're on your own with Windows ;) is:

    cd /path/to/my/jars

    grep -rli 'java/sql/PreparedStatement' .

This is a brute-force way of figuring out which jars contain which classes. It works because the "directory structure" of a ZIP file is plain text, not compressed.

Good luck! :)

我不确定,但如果你改变了最新的驱动程序

I also encountered this problem and found this question. I took the advice in the last answer, but I did not copy the tomcat-dbcp.jar, but just switched to a new version in my pom.xml and it works! Thanks for advice!

Had the same problem and solved by changing the driver library. The implementation of DelegatingPreparedStatement delegates the setCharacterStream call to its delegate, that's why changing the driver's implementation can solve the problem (if the implementation of the delegate includes that method)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM