Skip to content

Labels from one @NodeEntity class incorrectly added to nodes of different @NodeEntity class #1355

@Dev205

Description

@Dev205

Environment (Also verified with newer versions)

  • Neo4j OGM Version: 3.3.5-
  • Neo4j Driver Version: 4.4.19

Basic structure of classes

@NodeEntity
public abstract class BaseEntity {
    @Id @GeneratedValue
    private Long id;  // Neo4j internal ID
    private String name;
    private String workspaceId;
}

@NodeEntity
public class Product extends BaseEntity {
    private String productCode;
    private String category;
}

@NodeEntity
public class Document extends BaseEntity {
    private String documentId;
    private String type;
}

When using session.save() to update entities during the processing of the data, labels from one entity class are being added to nodes of a completely different entity class and not in the hierarchy.

Example:

A Document node (with label Document) receives additional labels BaseEntity and Product
This results in a node having labels: ["Document", "BaseEntity", "Product"]

This causes AmbiguousBaseClassException when querying:

org.neo4j.ogm.exception.core.AmbiguousBaseClassException: 
Multiple classes found in type hierarchy that map to: [Document, BaseEntity, Product]

Workaround
Changing from Neo4j internal IDs to UUID-based IDs resolves the issue:

@NodeEntity
public abstract class BaseEntity {
    @Id @GeneratedValue(strategy = UuidStrategy.class)
    private String id;  // UUID instead of Neo4j internal ID
    private String name;
    private String workspaceId;
}

After this change:

  • Labels are correctly assigned to their respective entity types
  • No AmbiguousBaseClassException occurs
  • Nodes maintain only their correct labels

Just trying to figure out what might be wrong with the current processing as it reliably occurs with a small dataset. Are ids being reused? Is the session giving ids and merging etc.

I've tried fixing it various ways i.e. clear session, explicit new sessions, explicit labels etc. Nothing really seems to help me solve the cause of this. I don't mind using the UUID, i just want to know what the issue is.

Edit:
There is a delete during the processing of Document nodes, and when I remove this it seems to fix the occurrence of AmbiguousBaseClassException.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions