英文:
NoSuchRecordException when saving Entity on Neo4j
问题
I am able to save an entity on my local PC using Neo4j Desktop version "5.3.0" but when I have the same exact same code and try saving the entity on the remote server with older version of "4.2.5, I am getting the below error;
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
@Repository
public interface OntologyRepository extends Neo4jRepository<Ontology, String> {
}
Service
@Service
public class OntologyService {
@Autowired
private OntologyRepository ontologyRepository;
public void saveProfile(Ontology ontology) {
ontologyRepository.save(ontology);
}
}
Entity
@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.
}
In the Service class, If the return type was also the object that I am trying to save, I would understand the error but that is not the case. I am just trying to save without querying any data. Any help would be great. Thanks
英文:
I am able to save an entity on my local PC using Neo4j Desktop version "5.3.0" but when I have the same exact same code and try saving the entity on the remote server with older version of "4.2.5, I am getting the below error;
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
@Repository
public interface OntologyRepository extends Neo4jRepository<Ontology, String> {
}
Service
@Service
public class OntologyService {
@Autowired
private OntologyRepository ontologyRepository;
public void saveProfile(Ontology ontology) {
ontologyRepository.save(ontology);
}
}
Entity
@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.
}
In the Service class, If the return type was also the object that I am trying to save, I would understand the error but that is not the case. I am just trying to save without querying any data. Any help would be great. Thanks
答案1
得分: 2
The error message Expected a result with a single record, but this result contains at least one more. Ensure your query returns only one record.
states that there is more than one record, with the same primary key. I believe this is due to your hash
key not being unique across nodes, as it is marked with @Id
. If you are not assigning hash
manually, then you should auto-generate it like this:
@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.
}
This should resolve the error.
英文:
The error message Expected a result with a single record, but this result contains at least one more. Ensure your query returns only one record.
, states that there is more than one record, with the same primary key. I believe this is due to your hash
key not being unique across nodes, as it is marked with @Id
. If you are not assigning hash
manually, then you should auto-generate it like this:
@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.
}
This should resolve the error.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论