Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-29-2021 01:44 AM
I have reached a state where there was a piece of code which deleted the nodes without deleting the relationships of the same. Now I am frequently getting node with node id not found error. Is there a way I can delete such relationships and indexes and any other such entities which can stop the node not found error?
07-29-2021 01:59 AM
Neo4j normally prevents you from deleting a node if you haven't deleted its relationships in a previous or in the same transaction. The transaction should not commit in that case.
Would you mind sharing the code at play here?
07-29-2021 02:12 AM
This is the error
rg.neo4j.graphdb.NotFoundException: Node 47643382 not found
at org.neo4j.kernel.impl.factory.GraphDatabaseFacade.getNodeById(GraphDatabaseFacade.java:228)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacade$3.apply(GraphDatabaseFacade.java:526)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacade$3.apply(GraphDatabaseFacade.java:522)
at org.neo4j.collection.primitive.PrimitiveLongCollections$14.next(PrimitiveLongCollections.java:746)
at org.neo4j.helpers.collection.ResourceClosingIterator.next(ResourceClosingIterator.java:76)
...
Caused by: org.neo4j.kernel.api.exceptions.EntityNotFoundException: Unable to load NODE with id 47643382.
... 76 common frames omitted
This piece of error is from below:
while (parentNodes.hasNext())
{
Node parentEntityNode = parentNodes.next(); - At this line.
...
}
Delete of the node code is:
try (Transaction tx = graphDb.beginTx())
{
boolean deleted = deleteNodeFromPlane(label, key, value);
tx.success();
}
catch (Exception e)
{
String errMessage = "Error in deleting nodes";
LOGGER.error(errMessage, e);
throw new GraphException(errMessage, e);
}
private boolean deleteNodeFromPlane(String label, String key, Object value)
{
Node node = graphDb.findNode(label, key, value);
node.delete();
return true;
}
07-29-2021 08:15 AM
Can you show the code around this as well?
Just to see where parentNodes
is defined and what the transactional context is.
07-29-2021 08:34 AM
This is the whole flow of code with transaction flow in it.
public void updateMeta(Metadata metadata) throws Exception {
try (Transaction tx = graphDb.beginTx())
{
saveMeta(products, company);
tx.success();
}catch (Exception e)
{
//Exception Handling
}
}
private void saveMeta(List products, String company) {
try
{
Node tenantNode = graphDb.findNode(key,label,value);
for (String product : products)
{
if (tenantNode.hasProperty(product))
{
persistMetaForProduct(tenantNode, product, company);
}
}
}
catch (Exception e)
{
//exception handling
}
}
private void persistMetaForProduct(Node tenantNode, String product, String company)
{
ResourceIterator<Node> parentNodes;
parentNodes = graphDb.findNodes(
DynamicLabel.label(key,label,value);
while (parentNodes.hasNext())
{
Node parentEntityNode = parentNodes.next();
//other line of code
}
}
07-29-2021 08:37 AM
Just to add another point is that, we have not added any transaction.failure() anywhere. we have always used try with resources and within that if no exception, transaction.success() as show in the above code.
All the sessions of the conference are now available online