Search code examples
javaneo4jgraph-databasesspring-data-neo4jneo4j-ogm

org.neo4j.ogm.exception.core.MappingException: More than one class has simple name


I have created 2 classes with same ClassName but in different packages and with different NodeEntity Labels. I'm facing below OGM Mapping Exception, only when invoking a repository method using @Query.

Caused by: org.neo4j.ogm.exception.core.MappingException: More than one class has simple name: Circuit
    at org.neo4j.ogm.metadata.DomainInfo.getClassInfo(DomainInfo.java:307)
    at org.neo4j.ogm.metadata.DomainInfo.getClassSimpleName(DomainInfo.java:289)
    at org.neo4j.ogm.metadata.MetaData.classInfo(MetaData.java:78)
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.lambda$executeAndMap$1(ExecuteQueriesDelegate.java:119)
    at org.neo4j.ogm.session.Neo4jSession.doInTransaction(Neo4jSession.java:574)
    at org.neo4j.ogm.session.Neo4jSession.doInTransaction(Neo4jSession.java:553)
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.executeAndMap(ExecuteQueriesDelegate.java:118)
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:88)
    at org.neo4j.ogm.session.Neo4jSession.query(Neo4jSession.java:408)

On debugging, I have found that the executeAndMap method in org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate class is using the Class SimpleName, and not the assigned label, to find the ClassInfo, which is causing the issue.

The classes with same simple name are present in different packages, with different labels and mapped with different repository interfaces. The Neo4jSession.loadAll works as expected as it uses the class full-qualified-name to get the ClassInfo.

private <T> Iterable<T> executeAndMap(Class<T> type, String cypher, 
                Map<String, ?> parameters, ResponseMapper mapper) {

        return session.<Iterable<T>>doInTransaction( () -> {
            if (type != null && session.metaData().classInfo(type.getSimpleName()) != null) {

Expected: NodeEntity Label to be used to get the ClassInfo.

Actual: Class SimpleName is being used to get the ClassInfo.


Solution

  • Using Class FullQualifiedName to get the ClassInfo works perfectly.

    It has been fixed. Reference below,

    Mapping Exception for entities with same Simple ClassName but different Labels