zoukankan      html  css  js  c++  java
  • Neo4j Required identifier property not found for class

    spring cloud Alibaba 微服务项目如下错误:

    Caused by: java.lang.IllegalStateException: Required identifier property not found for class com.huajun.kgbuilder.domainmodel.Movie!
        at org.springframework.data.mapping.PersistentEntity.getRequiredIdProperty(PersistentEntity.java:106)
        at org.springframework.data.repository.core.support.PersistentEntityInformation.getIdType(PersistentEntityInformation.java:74)
        at org.springframework.data.neo4j.repository.support.Neo4jRepositoryFactory.getTargetRepository(Neo4jRepositoryFactory.java:72)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:319)
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:323)
        at org.springframework.data.util.Lazy.getNullable(Lazy.java:230)
        at org.springframework.data.util.Lazy.get(Lazy.java:114)
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:329)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782)
        ... 46 common frames omitted
    09:13:13.752 [Thread-33] WARN  c.a.n.c.h.HttpClientBeanHolder - [shutdown,108] - [HttpClientBeanHolder] Start destroying common HttpClient
    Disconnected from the target VM, address: '127.0.0.1:1654', transport: 'socket'
    
    Process finished with exit code 1

    原因:微服务项目的jar包

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

    实体类定义如下引用的是ogm包下文件,需要换成org.springframework.data.neo4j包下的文件
    import org.neo4j.ogm.annotation.GeneratedValue;
    import org.neo4j.ogm.annotation.Id;
    import org.neo4j.ogm.annotation.NodeEntity;
    import org.neo4j.ogm.annotation.Property;
    正确配置
    package com.huajun.kgbuilder.domainmodel;
    
    import java.util.Collections;
    import java.util.HashSet;
    import java.util.Optional;
    import java.util.Set;
    import java.util.stream.Collectors;
    
    import org.springframework.data.neo4j.core.schema.Id;
    import org.springframework.data.neo4j.core.schema.Node;
    import org.springframework.data.neo4j.core.schema.Property;
    import org.springframework.data.neo4j.core.schema.Relationship;
    import org.springframework.data.neo4j.core.schema.GeneratedValue;
    import org.springframework.data.neo4j.core.support.UUIDStringGenerator;
    
    @Node
    public class Person {
    
    
    //    @Id @GeneratedValue(UUIDStringGenerator.class)
    //    private String id;
    
    //    @Id @GeneratedValue(generatorRef = "myIdGenerator")
    //    private String id;
    
        @Id
        @GeneratedValue
        private Long id;
    
        private String name;
    
        private Person() {
            // Empty constructor required as of Neo4j API 2.0.5
        }
    
        ;
    
        public Person(String name) {
            this.name = name;
        }
    
        /**
         * Neo4j doesn't REALLY have bi-directional relationships. It just means when querying
         * to ignore the direction of the relationship.
         * https://dzone.com/articles/modelling-data-neo4j
         */
        @Relationship(type = "TEAMMATE")
        public Set<Person> teammates;
    
        public void worksWith(Person person) {
            if (teammates == null) {
                teammates = new HashSet<>();
            }
            teammates.add(person);
        }
    
        public String toString() {
            return this.name + "'s teammates => "
                    + Optional.ofNullable(this.teammates).orElse(
                    Collections.emptySet()).stream()
                    .map(Person::getName)
                    .collect(Collectors.toList());
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    }




  • 相关阅读:
    2015-05-27 用正则把oracle时间转化到mysql时间
    linux版idea14界面美观和windows,mac基本一致
    ubuntu 下自定义快捷键,,用着舒服
    ubuntu 方便好用的截图软件
    Integer 包装器类 大小比较
    win7、ubuntu双系统,遇到分区不可用问题,和卸载ubuntu后win7开不了机
    巧妙小思想
    读取16进制文件和校验图片格式的问题。 文件名后缀
    旧电脑变废为宝!
    Win10打开Autodesk软件时提示“管理员已阻止你运行此应用”
  • 原文地址:https://www.cnblogs.com/Jeely/p/15194083.html
Copyright © 2011-2022 走看看