Search code examples
neo4jspring-data-neo4j

Error creating Neo4j repository: "The schema already contains a node description under the primary label"


The project contains the following files.

MyGoogleCalendarNeo4jRepository.java:

import org.springframework.data.repository.CrudRepository;

public interface MyGoogleCalendarNeo4jRepository extends CrudRepository<MyGoogleCalendar, String> {}

MyGoogleCalendar.java:

import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Relationship;

public class GoogleCalendarCalendar {

    @Relationship(type = "ASSOCIATED_TO", direction = Relationship.Direction.OUTGOING)
    private Calendar calendar;
    @Id
    private String id;

    /*
     * Default getters and setters
     */
    ...
 }

Calendar.java:

import org.springframework.data.neo4j.core.schema.Id;

public class Calendar {

    @Id
    private String id;
    private com.google.api.services.calendar.Calendar service;

    /*
     * Default getters and setters
     */
    ...
 }

When I try to run the project, I get the following error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name [...] nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myGoogleCalendarNeo4jRepository' defined in com.[...].MyGoogleCalendarNeo4jRepository defined in @EnableNeo4jRepositories declared on MyApplication: Invocation of init method failed; nested exception is org.springframework.data.mapping.MappingException: The schema already contains a node description under the primary label Calendar


Solution

    • Option 1: Change the name of the project class.

    E.g.: from Calendar to MyCalendar

    • Option 2: Make the Google Calendar property transient.

    Calendar.java:

    import org.springframework.data.annotation.Transient;
    import org.springframework.data.neo4j.core.schema.Id;
    
    public class Calendar {
    
        @Id
        private String id;
        @Transient
        private com.google.api.services.calendar.Calendar service;
    
        /*
         * Default getters and setters
         */
        ...
     }