Foofighter2146
Foofighter2146

Reputation: 71

Using Cypher from Scala in embedded databases fails

I use neo4j-jdbc 2.0.2 from Scala 2.11.1 and Neo4J database 2.0.3. While firing Cypher queries to a Neo4J server via rest interface works very well, the usage of Cypher queries within an embedded database fails. After researching a ittle bit in Neo4J sources I found that the reason is inside the Cypher API while calling the execution inside the ExecutionEngine. What can I do to fix it?

def main(args: Array[String]) {
  val db = new GraphDatabaseFactory().newEmbeddedDatabase("D:/Datenbanken/neo4j/testsnn")
  val engine = new ExecutionEngine(db)
  val result = engine.execute("MATCH (n) return n")
  println(result)
}

Execution of this code produces at run time

Exception in thread "main" java.lang.NoClassDefFoundError: scala/runtime/AbstractPartialFunction$mcVL$sp
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.neo4j.cypher.internal.compiler.v2_0.executionplan.verifiers.HintVerifier$.<init>(HintVerifier.scala:31)
at org.neo4j.cypher.internal.compiler.v2_0.executionplan.verifiers.HintVerifier$.<clinit>(HintVerifier.scala)
at org.neo4j.cypher.internal.compiler.v2_0.CypherCompiler.<init>(CypherCompiler.scala:33)
at org.neo4j.cypher.internal.CypherCompiler$VersionProxy.<init>(CypherCompiler.scala:47)
at org.neo4j.cypher.internal.CypherCompiler$.apply(CypherCompiler.scala:37)
at org.neo4j.cypher.ExecutionEngine$$anonfun$org$neo4j$cypher$ExecutionEngine$$createCompiler$2.apply(ExecutionEngine.scala:131)
at org.neo4j.cypher.ExecutionEngine$$anonfun$org$neo4j$cypher$ExecutionEngine$$createCompiler$2.apply(ExecutionEngine.scala:129)
at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:185)
at org.neo4j.cypher.ExecutionEngine.org$neo4j$cypher$ExecutionEngine$$createCompiler(ExecutionEngine.scala:133)
at org.neo4j.cypher.ExecutionEngine$$anonfun$2.apply(ExecutionEngine.scala:78)
at org.neo4j.cypher.ExecutionEngine$$anonfun$2.apply(ExecutionEngine.scala:78)
at org.neo4j.cypher.ExecutionEngine$$anon$1.apply(ExecutionEngine.scala:119)
at org.neo4j.cypher.ExecutionEngine$$anon$1.apply(ExecutionEngine.scala:118)
at org.neo4j.kernel.impl.api.KernelSchemaStateStore.getOrCreate(KernelSchemaStateStore.java:72)
at org.neo4j.kernel.impl.api.SchemaStateConcern.schemaStateGetOrCreate(SchemaStateConcern.java:37)
at org.neo4j.kernel.impl.api.LockingStatementOperations.schemaStateGetOrCreate(LockingStatementOperations.java:124)
at org.neo4j.kernel.impl.api.OperationsFacade.schemaStateGetOrCreate(OperationsFacade.java:412)
at org.neo4j.cypher.ExecutionEngine.getOrCreateFromSchemaState(ExecutionEngine.scala:121)
at org.neo4j.cypher.ExecutionEngine.prepare(ExecutionEngine.scala:77)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:59)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:54)
at org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:65)
at de.richertt.scalaneonodes.example.Main2$.main(Main2.scala:17)
at de.richertt.scalaneonodes.example.Main2.main(Main2.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)s

Upvotes: 3

Views: 919

Answers (3)

Michael Pollmeier
Michael Pollmeier

Reputation: 1380

Update: Neo4j is now compatible with Scala 2.11, I have just updated the example for gremlin-scala: https://github.com/mpollmeier/gremlin-scala-examples

Upvotes: 1

Daniel Macias
Daniel Macias

Reputation: 282

Resuming further still on Foofighter2146, I'd like to suggest not holding your breath on Scala 2.11 support. As said by cleishm

A database is a complex piece of software, and updating the internal dependencies is not something done lightly or quickly, especially for something as fundamental as the scala version. So while we'd like to provide a timeframe for doing so, it is not possible at this stage. Supporting multiple versions with combinations of dependencies is also not something we are able to do at this time.

along with an excellent suggestion

I highly recommend that you minimize the amount of code running in the same JVM as the Neo4j libraries, and avoid anything that has additional dependencies or dependencies that are incompatible with what Neo4j currently requires. Ideally, consider using Neo4j Server instead - and writing any bespoke software as a plugin or unmanaged extension.

I'm using Neo4j's Traversal framework so I can use more advanced traversals. After finding a few limitations with embdedded version, I will be moving my traversals to an extention.

Cheers.

Upvotes: 1

Foofighter2146
Foofighter2146

Reputation: 71

Resuming the useful comments from Mikesname and Michael Hunger I am able to answer the question by myself: If I want to use the embedded version of Neo4j database from Scala with Cypher queries, I have to use the same Scala version that is used for Cypher implementation (currently Scala 2.10), because it runs both in the same JRE.

Upvotes: 4

Related Questions