-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toMany relationshipEntity is detached after first update #868
Comments
Similar (or same ?) as spring-projects/spring-data-neo4j#2130 |
Hi. OGM needs to flush the session cache on custom queries on which it can not reliable decide whether it's a read or write query (we don't do client Cypher parsing). This can be fixed with a query hint: private void runReadQuery(Actor entity) {
Map<String, Object> params = new HashMap<>();
params.put("id", entity.getId());
session.query("MATCH /*+ OGM_READ_ONLY */ path = (a:Actor)-[:PLAYED_IN*0..]->()"
+ " WHERE id(a) = $id"
+ " RETURN nodes(path), relationships(path)", params);
} Please see this #839 Please let me now if this works for you. |
See neo4j/neo4j-ogm#868 => the issue still persists
Hi @michael-simons, thanks for the feedback Alas, it doesn't solve the issue, even after adding the hint |
I am sorry for this longtime until "needs investigation" was concluded. If you look into the database, all relationships are consisted. OGM however is not able to figure out that the one relationship has already been loaded. You need to add a proper pair of @Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Role role = (Role) o;
return Objects.equals(relationshipId, role.relationshipId);
}
@Override
public int hashCode() {
return Objects.hash(relationshipId);
} Of course, a better implementation is to do this for Read only hint is not needed btw but I recommend it nevertheless. Thanks again for opening this up. |
Thanks very much @michael-simons My issue (in my real project) was resolved by using the 2 instructions you gave me:
Thanks once more !!! |
Thanks a lot for your feedback, @gonzalad much appreciated. |
Hello, I have the following issue
If needed there's a sample project to reproduce this issue : https://github.com/gonzalad/neo4j-dependent-relationship-entity-issue/blob/master/src/test/java/com/example/neo4j/IssueTest.java
Issue
When using relationshipEntities to model toMany relations, when executing a series of updates/queries on the root entity (all in the same transactional context), the relationshipEntity can get detached.
We end up with a 2 instances of the same relationshipEntity in the root entity.
Expected Behavior
I would expect that in a given transactional context every entity and every relation is attached (session OGM keeps track of maintaining the references between entity instances).
Current Behavior
My test case is:
Sample test failing:
In the following test, the last line
Should return a size of 1 but it instead returns a size of 2.
From what I understand, the entities id are the same, but the instances are different hence from my POV, one of them has been detached under the hoods by the previous save (update) operation.
Testcase
Entity classes used by the sample (based on Spring Boot sample Actor/Role/Movie, but I changed role cardinality to be ToMany):
Context
When issuing series of updates/queries in my real application I have duplicated relation instances.
This messes up the application and makes it really hard to use relationshipEntities in ToMany scenarios.
Your Environment
Thanks,
Adrian
The text was updated successfully, but these errors were encountered: