在Neo4j上保存实体时出现NoSuchRecordException

wi3ka0sx  于 2023-05-17  发布在  其他
关注(0)|答案(1)|浏览(446)

我可以使用Neo4j桌面版本“5.3.0”在本地PC上保存实体,但当我使用完全相同的代码并尝试使用旧版本“4.2.5”在远程服务器上保存实体时,我得到以下错误;

2023-05-11 09:48:13.525  WARN 90586 --- [  poolThread-96] .n.c.Neo4jPersistenceExceptionTranslator : Don't know how to translate exception of type class org.neo4j.driver.exceptions.NoSuchRecordException
Exception in thread "poolThread-96" org.neo4j.driver.exceptions.NoSuchRecordException: Expected a result with a single record, but this result contains at least one more. Ensure your query returns only one record.

仓库

@Repository

public interface OntologyRepository extends Neo4jRepository<Ontology, String> {
}

服务项目

@Service
public class OntologyService {
      @Autowired
      private OntologyRepository ontologyRepository;

      public void saveProfile(Ontology ontology) {
        ontologyRepository.save(ontology);
      }
}

实体

@Data
@EqualsAndHashCode(callSuper = false)
@JsonIgnoreProperties(ignoreUnknown = true)
@Node("Profile")
@Component
public class Ontology extends Profile implements Cloneable {

    @Id
    private String hash;

    @Transient
    private long id;

    //etc.
}

在Service类中,如果返回类型也是我试图保存的对象,我会理解错误,但事实并非如此。我只是想保存而不查询任何数据。任何帮助将是伟大的。谢谢

du7egjpx

du7egjpx1#

错误消息Expected a result with a single record, but this result contains at least one more. Ensure your query returns only one record.指出有多个记录具有相同的主键。我认为这是由于您的hash密钥在节点之间不唯一,因为它标记为@Id。如果你没有手动分配hash,那么你应该像这样自动生成它:

@Data
@EqualsAndHashCode(callSuper = false)
@JsonIgnoreProperties(ignoreUnknown = true)
@Node("Profile")
@Component
public class Ontology extends Profile implements Cloneable {

    @Id
    @GeneratedValue(generatorClass = UUIDStringGenerator.class)
    private String hash;

    @Transient
    private long id;

    //etc.
}

这应该可以解决错误。

相关问题