[io.r2dbc.spi.ConnectionFactory]: java.lang.NoSuchFieldError: LOCK_WAIT_TIMEOUT - spring-data-r2dbc

My Java Spring Boot project fails at startup with the given error:
Failed to instantiate [io.r2dbc.spi.ConnectionFactory]: Factory method 'connectionFactory' threw exception; nested exception is java.lang.NoSuchFieldError: LOCK_WAIT_TIMEOUT
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-r2dbc</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>com.oracle.database.r2dbc</groupId>
<artifactId>oracle-r2dbc</artifactId>
<version>0.4.0</version>
</dependency>
How do I fix it?

tl;dr: As of this writing, use oracle-r2dbc 0.1.0 in Spring projects.
oracle-r2dbc 0.4.0 depends on a newer version of io.r2dbc:r2dbc-spi than spring-data-r2dbc 1.4.3.
You may have to clear your build tool or IDE's cache for the change to take effect. (In my case mvn clean and IntelliJ "Invalidate Caches...")
Btw, when I downgraded, I think it broke using descriptors in the rdbc URL so I had to switch to a URL like this: r2dbc:oracle://<host>:<port>/<service-name>
Update, just saw on Oracle's driver docs for r2dbc, it says:
Use the 0.1.0 version of Oracle R2DBC if you are programming with
Spring. The later versions of Oracle R2DBC implement the 0.9.x
versions of the R2DBC SPI. Currently, Spring only supports drivers
that implement the 0.8.x versions of the SPI.
https://github.com/oracle/oracle-r2dbc
DO NOT USE 0.2.0 with Spring - even worse than no error, queries just hang forever. I spent over a day trying to debug it. Not only I had the wrong version, but when I actually did try changing the version, my IDE was caching the old version out of sync with Maven.

Related

Optaplanner - drools file cannot be compiled when project is deployed

We developped a SpringBoot project with Java 11 using optaplanner-core and defining rules in a Drools file. We have no issue for running the app in intelliJ with JDK.
We then deployed the app onto Azure app service where a JRE is installed. We get the following error:
Caused by: org.kie.memorycompiler.KieMemoryCompilerException:
Cannot find the System's Java compiler. Please use JDK instead of JRE or add drools-ecj dependency to use in memory Eclipse compiler
We tried to add the following dependencies but we still get the same error:
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-core</artifactId>
<version>8.4.1.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-ecj</artifactId>
<version>7.51.0.Final</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.26.0</version>
</dependency>
Would anyone know how to solve this problem ?
Thank you
Adding drools-ecj won't really fix this. The error message is misleading.
Using a JDK instead of a JRE. The easiest way is to upgrade to Java 11 (or higher), as that only comes with a JDK.
If running optaplanner with a JDK is no option for you, you can change the solver config to
<solver>
<scoreDirectorFactory>
<droolsAlphaNetworkCompilationEnabled>false</droolsAlphaNetworkCompilationEnabled>
</scoreDirectorFactory>
</solver>
and if you're using unit tests for java constraints that use the ConstraintVerifier, instantiate it like this
new DefaultConstraintVerifier<>(new MyConstraints(), SolutionDescriptor.buildSolutionDescriptor(myModelClasses))
.withDroolsAlphaNetworkCompilationEnabled(false)
However: From what I understood, disabling the drools alpha network compiler usually comes with a performance impact.

saveToCassandra with spark-cassandra connector throws java.lang.ClassCastException

When trying to save data to Cassandra(in Scala), I get the following exception:
java.lang.ClassCastException:
com.datastax.driver.core.DefaultResultSetFuture cannot be cast to
com.google.common.util.concurrent.ListenableFuture
Please note that I do not get this error every time, but it comes up randomly once in a while which makes it more dangerous in production.
I am using YARN and I have shaded com.google.** to avoid the Guava symbol clash.
Here's the code snippet:
rdd.saveToCassandra(keyspace,"movie_attributes", SomeColumns("movie_id","movie_title","genre"))
Any help would be much appreciated.
UPDATE
Adding details from the pom file as requested:
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector_2.10</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector-java_2.10</artifactId>
<version>1.5.0</version>
</dependency>
**Shading guava**
<relocation> <!-- Conflicts between Cassandra Java driver and YARN -->
<pattern>com.google</pattern>
<shadedPattern>oryx.com.google</shadedPattern>
<includes>
<include>com.google.common.**</include>
</includes>
</relocation>
Spark version: 1.5.2
Cassandra version: 2.2.3
Almost everyone who works on C* and Spark has seen these type of errors. The root cause is explained here.
C* driver depends on a relatively new version of guava while Spark depends on an older guava. To solve this before connector 1.6.2, you need to explicitly embed C* driver and guava with your application.
Since 1.6.2 and 2.0.0-M3, by default connector ships with the correct C* driver and guava shaded. So you should be OK with just connector artifact included in your project.
Things get tricky if your Spark application uses other libraries that depend on C* driver. Then you will have to manually include un-shaded version of connector, correct C* driver and shaded guava and deploy a fat jar. You essentially make your own connector package. In this case, you can't use --package to launch Spark cluster anymore.
tl;dr
use connector 1.6.2/2.0.0-M3 or above. 99% you should be OK.

MongoDB Java driver 3.0 error

I use java driver 3.0 using gradle, I got:
java.lang.NoClassDefFoundError: org/bson/io/InputBuffer
at org.mongodb.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:42)
Any help?
I use github source and make it. Everything is well now. I think that the snapshot version has some problem.
I met same problem several days ago, here is the solution:
Change to mongo-java-driver-3.0.0-SNAPSHOT, not mongodb-driver-3.0.0-SNAPSHOT.
Seems like mongo java driver changed it's artifactiId (for maven)
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
Since your using gradle, here is the correct java library for mongo 3.0
'org.mongodb:mongo-java-driver:3.0.0-rc1'

Best version of the mongodb gorm plugin for grails 2.2.x?

Will the current MongoDB GORM plugin work on grails 2.2.x versions ? Specifically grails 2.2.3.
Just a note, upgrading to grails 2.3 is really not an easy option for this app.
After a few tests, the last version of the mongodb Grails plugin compatible with Grails 2.2.x (2.2.4 in my case) seems to be 1.3.3.
Trying to use the version after (2.0.0) gives the following:
Plugin mongodb-2.0.0 requires version [2.3.2 > *] of Grails which your current Grails installation does not meet
You can use the latest one: 3.0.1
This version has support for mongodb 2.6
After experimenting with various combinations.
I have found that it's the 1.3.3 version of mongodb that worked for my grails version 2.2.3.
additional notes:
I also had to use the 1.1.9 versions grails-datastore-core and grails-datastore-simple
as the 1.1.8 versions were causing a class def not found for StatelessDatastore.
I use maven for my build so the final dependencies I added look like this:
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>mongodb</artifactId>
<version>1.3.3</version>
<scope>compile</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-datastore-core</artifactId>
<version>1.1.9.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-datastore-simple</artifactId>
<version>1.1.9.RELEASE</version>
<scope>compile</scope>
</dependency>
Thanks for the replies everyone.
watch out!
mongo 3.0.1 uses updated version of gorm/hibernate libs, which are incompatible with the ones delivered with hibernate:3.6.10.13 (the most recent version is 3.6.10.14, but when I try getting it, the dependency couldn't be resolved). That means, that the libs in the older versions of hibernate plugin can not be newer than that.
see or in namedQueries in Grails 2.3.8: AbstractMethodError for details.
I had to switch from 3.0.1 back to 3.0.0. If you want to upgrade you mongo java driver, you can do it via dependencies w/o upgrading the grails plugin. Heck! I even used aggregation in mongodb:1.0.0.RC3 :)

Appengine + Maven + Spring + Eclipse

I want to use maven and spring with appengine, but I can't...
I was able to configure maven with appengine (and spring with appengine, but without maven), but when I add spring dependencies and I try to run it I have the following error:
WARNING: Could not instantiate listener org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
[...]
java.lang.ClassNotFoundException: org.springframework.web.filter.CharacterEncodingFilter
how I can solve this problem?
I read tons of information but it seems out to date...
Thanks, and sorry for my english.
It would help if you put more info into your question, but I would say to take a look at the spring artifacts here in maven central : http://search.maven.org/#search%7Cga%7C1%7Corg.springframework and try to choose all a single version that works for you. I think they are on 3.2.2.RELEASE
Sorry I can't be of more help, but since the springframework docs are a bit outdated for maven support these days (http://www.springsource.org/spring-framework), it can be easy to get a mishmash of versions which cause issues with resolving dependencies.
Try also only declaring the minimum set of dependencies you can, and "mvn dependency:tree" can also clue you into where you might be bringing in duplicate dependencies, which can cause this type of problem.
For maven dependancies please have a look at:
https://mvnrepository.com/artifact/org.springframework
Make sure you have spring-web dependancy declared.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${springframework.version}</version>
</dependency>
Please read the appengine spring optimization guide, can save you some hassle later on:
https://cloud.google.com/appengine/articles/spring_optimization