我可以使用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类中,如果返回类型也是我试图保存的对象,我会理解错误,但事实并非如此。我只是想保存而不查询任何数据。任何帮助将是伟大的。谢谢
1条答案
按热度按时间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
,那么你应该像这样自动生成它:这应该可以解决错误。