Cypher query works in Neo4J browser, but not run in Java

I'm trying to create a new node that is linked to an existing node for which I have the elementId. I wrote this query in the Neo4J browser to verify what I wanted to do actually worked:

MATCH (newApp: system⚁⚁application) WHERE elementId(newApp) = '4:c27fa6be-0d0f-4662-9e30-b4e7302b9104:1'

CREATE (newApp) -[:RecordType]-> (newRecordType: system⚁⚁recordType {spaceName: 'Test', recordType:'StringTest'})

RETURN elementId(newRecordType)

With a result of:

╒══════════════════════════════════════════╕
│elementId(newRecordType) │
╞══════════════════════════════════════════╡
│"4:c27fa6be-0d0f-4662-9e30-b4e7302b9104:2"│
└──────────────────────────────────────────┘

Then I wrote the code to create the equivalent of the same query for running with the Java driver:

MATCH (newApp: system⚁⚁application) WHERE elementId(newApp) = '4:24d5928d-24a7-401f-bf3f-7ff4fb7766dd:47'

CREATE (newApp) -[:RecordType]-> (newRecordType: system⚁⚁recordType $props)

RETURN elementId(newRecordType)

Where the query properties are: {props={spaceName=Test, recordType=StringTest}}

With a result of:

+--------------------------+
| elementId(newRecordType) |
+--------------------------+
+--------------------------+
0 row

So clearly, I'm doing something wrong here, but I just don't see it. I would greatly appreciate any feedback or suggestions that anyone might have to offer here.

Thank you

Your query performs a match, followed by a create. As such, the newRecordType node should be created and related to the the newApp node. The only cause I can think of is the newApp node did not match. Your elementId's are different between the two queries. Can this be the cause? If not, do you get a result when you execute just the match?

MATCH (newApp: system⚁⚁application) WHERE elementId(newApp) = '4:24d5928d-24a7-401f-bf3f-7ff4fb7766dd:47'
return newApp

The IDs don't match because it's two different runs. The Java is running in a unit test, so the IDs are constantly different - a previous part of the unit test creates the node for newApp and returns its ID, and that ID is what's used in this query.

But I'll try your suggestion, just to make sure that part is actually working.

1 Like

I did just the query - and figured out the problem.

In the browser, it was auto-committing. In Java, I was missing the commit. Careless of me.

You don’t use transaction functions?

Yes, but I had just overlooked putting in the correct commits.

Very silly.

Transaction functions do not require computing. They will commit if the transaction doesn’t throw an exception or you rollback.

Interesting. I will look into that. It might not be necessary the way most of my code its structured, so far, but there might come a point where that would turn out to be very handy.

1 Like