Spring data neo4j: Invalid syntax '$' in Cypher。 How to replace '$' with '{}'? - neo4j

The Cypher generated by spring data neo4j uses "$" to pass value, which will cause a error of Invalid Syntax by neo4j.
For example:
The Cypher generated by spring data neo4j for:
Optional<linkType> findById(Long id);
is
"MATCH ()-[r0:`linkType`]->() WHERE ID(r0)=$id WITH r0,STARTNODE(r0) AS n, ENDNODE(r0) AS m RETURN r0,n,m, ID(r0)"
This gets a error of Invalid Syntax.
I fixed this by use #Query:
#Query("MATCH ()-[r0:`linkType`]->() WHERE ID(r0)={id} WITH r0,STARTNODE(r0) AS n, ENDNODE(r0) AS m RETURN r0,n,m, ID(r0)")
Optional<linkType> findById(Long id);
However, when I want to use the PagingAndSortingRepository, I cannot use the #Query to fix this problem. Because it will add SKIP $sdnSkip LIMIT $sdnLimit at the edn automaticaly.
How can I fix this problem? Thanks.

You are using a really old version of neo4j (older than 3.0).
In neo4j 3.0, the {foo} syntax was deprecated in favor of the $foo syntax. In neo4j 4.0, the {foo} syntax was totally removed.
Instead of trying to support the obsolete {foo} syntax, you should upgrade your neo4j installation to a more recent (ideally, the latest) version of neo4j. If you have data to upgrade, you will have to upgrade in 2 steps:
From your current version to 3.5.
From 3.5 to 4.x.

Related

reactor-core version 3.1 breaks existing code

The code below is from the book Learning Spring Boot 2.0 by Greg Turnquist. It runs with reactor-core version 3.0.7. It won't compile with version 3.1.0 or later. In 3.0.7 the Mono.just().and() method returns a Mono<reactor.util.function.Tuple2<T, T2>>. In 3.1.0 it returns a Mono<Void>.
This is a really bad, breaking change in a minor revision. What do I need to do to make this code run under 3.1.0 and later?
Flux.just("alpha", "bravo", "charlie")
.map(String::toUpperCase)
.flatMap(s -> Flux.fromArray(s.split("")))
.groupBy(String::toString)
.sort((o1, o2) -> o1.key().compareTo(o2.key()))
.flatMap(group -> Mono.just(group.key()).and(group.count()))
.map(keyAndCount ->
keyAndCount.getT1() + " => " + keyAndCount.getT2())
.subscribe(System.out::println);
I'll post the answer for anyone else who runs into this. Simply replace the call to and() with a call to zipWith():
.flatMap(group -> Mono.just(group.key()).zipWith(group.count()))
It's very strange that the reactor team would make a breaking change in a minor revision.

dartium (chromium) error on yaml/src/loader.dart

I keep getting this
Internal error: 'package:yaml/src/loader.dart': error: line 197 pos 32: unexpected token '?'
_tryParseScalar(scalar) ?? new YamlScalar.internal(scalar.value, scalar)
?? is a quite new extension (null-aware operators) to the Dart syntax. You probably use a Dart version that doesn't support it.
Null aware operators were introduced with Dart 1.12
See https://github.com/dart-lang/sdk/blob/master/CHANGELOG.md#1120
You can check your current Dart version with dart --version on the command line.
The package using this new feature should have a SDK constraint that limits the package version to SDK versions that support this feature.

Cause of neo4j IndexOutOfBoundsException on getRelationships()

This is happening in neo4j version 2.3.0-M02
Why might this code ....
Iterable<Relationship> rels = node.getRelationships( ... any various args ... );
for (Relationship rel : rels) {
// Some computation
}
... cause this stack trace ?
Caused by: java.lang.IndexOutOfBoundsException
at org.neo4j.io.pagecache.impl.muninn.MuninnPageCursor.setOffset(MuninnPageCursor.java:410)
at org.neo4j.kernel.impl.store.RelationshipGroupStore.getRecord(RelationshipGroupStore.java:117)
at org.neo4j.kernel.impl.store.RelationshipGroupStore.getRecord(RelationshipGroupStore.java:77)
at org.neo4j.kernel.impl.api.StoreRelationshipIterable$DenseIterator.<init>(StoreRelationshipIterable.java:214)
at org.neo4j.kernel.impl.api.StoreRelationshipIterable.iterator(StoreRelationshipIterable.java:96)
at org.neo4j.kernel.impl.api.StoreRelationshipIterable.iterator(StoreRelationshipIterable.java:76)
at org.neo4j.kernel.impl.api.store.DiskLayer.nodeListRelationships(DiskLayer.java:241)
at org.neo4j.kernel.impl.api.store.CacheLayer.nodeListRelationships(CacheLayer.java:424)
at org.neo4j.kernel.impl.api.StateHandlingStatementOperations.nodeGetRelationships(StateHandlingStatementOperations.java:925)
at org.neo4j.kernel.impl.api.StateHandlingStatementOperations.nodeGetRelationships(StateHandlingStatementOperations.java:933)
at org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations.nodeGetRelationships(ConstraintEnforcingEntityOperations.java:426)
at org.neo4j.kernel.impl.api.OperationsFacade.nodeGetRelationships(OperationsFacade.java:361)
at org.neo4j.kernel.impl.core.NodeProxy$2.iterator(NodeProxy.java:194)
at org.neo4j.kernel.impl.core.NodeProxy$2.iterator(NodeProxy.java:186)
Update:
Issue #5691 on Github
Same bug again in version 2.3.0
You should upgrade to Neo4j 2.3.0-M03.
Milestone releases tend to be unstable and you are using old one. It is known that M02 has bugs, and lot of them are fixed in M03.
So, upgrade and check if this works for you.

Simple cypher query on embedded graph DB from Java results in nullpointerexception

Until now I have only interacted with neo4j through its browser and REST interface.
Now I want to interact with neo4j via Java and an embedded database.
I get a null pointer exception when I attempt to run a Cypher query.
The console output did not help me:
Exception in thread "main" java.lang.NullPointerException
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:58)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:54)
at org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:65)
at neo.project1.App.main(App.java:59)
My config
Ubuntu 14.04
neo4j/stable,now 2.0.2 all [installed]
java version "1.7.0_55"
Link to .java file and pom file
Try this:
ExecutionEngine engine = new ExecutionEngine(graphDb);
Sounds like your original constructor call (with the second parameter as NULL) is letting the ExecutionEngine try to use a NULL logger.

neo4j enterprise 1.8.1 Cypher ExecuteEngine bug?

I am running neo4j enterprise 1.8 on grails and wanted to upgrade to 1.8.1. As I am also using the Cypher Engine extensively, after upgrade I tried to execute some queries. Unfortunately I encountered an Exception when trying to initiate the Cypher ExecutionEngine.
I've written a small Service which does the work for me:
import org.neo4j.cypher.javacompat.ExecutionEngine
import org.neo4j.kernel.impl.util.StringLogger
class CypherService {
def graphDatabaseService
static transactional = true
def executeString(String cypherString) {
log.debug "start method executeString"
ExecutionEngine executionEngine = new ExecutionEngine(graphDatabaseService, StringLogger.DEV_NULL)
if(executionEngine) {
def result = executionEngine.execute(cypherString)
return result
} else {
log.error "Could not initialize the execution engine for Cypher"
return null
}
}
}
When initiating the Execution Engine, I got the following Exception:
java.lang.NoSuchMethodError: com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap$Builder.maximumWeightedCapacity(J)Lcom/googlecode/concurrentlinkedhashmap/ConcurrentLinkedHashMap$Builder;
at org.neo4j.cypher.internal.LRUCache.<init>(LRUCache.scala:31)
at org.neo4j.cypher.ExecutionEngine$$anon$1.<init>(ExecutionEngine.scala:91)
at org.neo4j.cypher.ExecutionEngine.<init>(ExecutionEngine.scala:91)
at org.neo4j.cypher.javacompat.ExecutionEngine.<init>(ExecutionEngine.java:54)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:202)
at com.netjay.fanorakel.CypherService.executeString(CypherService.groovy:16)
Any idea what is going wrong here, and is there a solution to avoid this?
Best
Michael
You could probably also just rebuild Neo4j's cypher module against the older version of the lib, or actually exclude the dependency from neo4j.
I had the same issue- with 1.8.1 I needed to separately include concurrentlinkedhashmap-lru.1.3.1.jar
http://code.google.com/p/concurrentlinkedhashmap/downloads/detail?name=concurrentlinkedhashmap-lru-1.3.1.jar&can=2&q=
The problem here is that:
Neo4j 1.8.1 introduced a new dependency to concurrentlinkedhashmap_lru version 1.3.1, AND
Grails has a dependency to concurrentlinkedhashmap_lru version 1.2_jdk5, AND
concurrentlinkedhashmap_lru's API is not backwards compatible for these two versions.
Therefore the grails codebase has been recently upgraded to move the dependency to 1.3.1, see https://github.com/SpringSource/grails-data-mapping/commit/b15e207a2a08ac16e77de399733cb9cc14eff48e and
https://github.com/grails/grails-core/commit/6dfab1a5db4da8c176351f23d65c7fc0d4aa6364.
So to use Neo4j 1.8.1 (and newer) with Grails you could either wait for a new Grails release or build a Grails snaptshot on your own.

Resources