Spring Data Neo4j MappingException: поле с первичным идентификатором для объекта является пустым - PullRequest
0 голосов
/ 31 января 2020

У меня есть класс сущности узла, который расширяет абстрактный класс, который, в свою очередь, расширяет другой абстрактный класс следующим образом:

public abstract class AbstractModel{
    @Id
    @GeneratedValue(strategy = UuidStrategy.class)
    @Convert(UuidStringConverter.class)
    protected UUID uuid;
}

public abstract class AbstractBayModel extends AbstractModel{
     .....//more protected fields
}

public class Person extends AbstractBayModel{
    private String name;
    .//more code
    .
    .
}

@Service
//Has a reference to a repository
public class PersonService{
   public void add(Person person){
      repository.insert(person);
   }
}

Теперь, когда я вызываю метод add () класса обслуживания, я получаю следующая ошибка.

org.neo4j.ogm.exception.core.MappingException: Field with primary id is null for entity model.Person@41a45331

Я попытался изменить метод обслуживания следующим образом и все еще получаю ту же ошибку:

public void add(Person person){
   person.setUuid(UUID.randomUUID();
   repository.insert(person);
}

Я использую следующие пружинные зависимости

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-neo4j</artifactId>
   </dependency>

Буду очень признателен, если кто-нибудь сможет помочь.

уважает



...