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

I have a very nasty problem and I can not find the answer anywhere.

My application throws this exception when trying to save @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 working on Tomcat 6.0.36 (also tried tomcat 7).

MySQL Database 4.1.22.

The code is compiled using jdk 7 and built using gradle.

My dependencies:

 +--- 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 (*) 

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

But to be honest, I'm at a loss, I've tried a lot of things, but I can't seem to get it to work ... 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> 
+4
source share
5 answers

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

My problem was that when I tried this on my tomcat 7 server, I still got the same error in one place in my application. This was caused by the old version of mysql-connector-java (5.0.5, if I remember correctly), which lingered in my tomcat lib folder due to earlier attempts to do this work. It looks like this old version took precedence over my own mysql-connector-java (newest version), which I have as a dependency. Since it gave me the same exception, it seemed that it did not change anything in my situation, while it really did.

When I realized this, the rest was easy, my only problem was that I couldn’t easily upgrade to tomcat 7, since other applications are currently running on our version of tomcat 6 in production. So the solution was to copy tomcat-dbcp.jar from the tomcat 7 server to our tomcat 6 server and replace the one that was already there.

Hope this helps others too, thanks to everyone for any help anyway!

+3
source

AbstractMethodError is a subclass of LinkageError that almost always indicates that something is wrong with your class paths - libraries that have not been compiled together are loaded together.

Assuming your library versions match my instant research ...

The line that throws the exception is DelegatingPreparedStatement: 328 . It looks like this:

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

If you switch to setCharacterStream , you will see that it is marked as @since 1.6 .

So you should:

  • Make sure you are running version 1.6+. :)

  • Check for other java.sql.PreparedStatement implementations anywhere in your classpath. As usual, I do this (on a Unix-like system, you're on your own with Windows;):

    cd /path/to/my/jars

    grep -rli 'java/sql/PreparedStatement' .

This is a brute force method for determining which banks contain classes. It works because the "directory structure" of the ZIP file is plain text, not compressed.

Good luck! :)

+3
source

I'm not sure, but if you changed using the latest driver

0
source

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

0
source

There was the same problem and was solved by changing the driver library. The DelegatingPreparedStatement implementation delegates the setCharacterStream call to its delegate, so changing the driver implementation can solve the problem (if the delegate implementation includes this method)

0
source

Source: https://habr.com/ru/post/1496825/


All Articles