-
Notifications
You must be signed in to change notification settings - Fork 616
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
Storing a relation with @RelationshipProperties corrupts existing relations if the relation is modeled bidirectional #2905
Comments
Hi @ma-ku thanks for your report. I have to say, "sorry, you're holding it wrong". A couple of things:
I will push a commit shortly demonstrating that and closing the issue. The commit will contain two solutions: First, you're fixed solution, storing the related entities separately. I would however recommend you to follow a solution in which you just persist your root aggregate. |
OK, you are right if the annotation is missing but I unfortunately stripped this when I removed all the additional annotations such as Lombok and such. The classes are annotated with This error occurred after we had introduced the abstract base class for the target nodes as we now wanted to model them as nested containers of items. Before that, we only had one concrete target entity and everything was fine. So I would ask you to double check this particular scenario. |
See 7d38286 I will be traveling the next 2 weeks, I would defer this than to @meistermeier next week. |
|
In our project we have encountered a strange behavior with relations with additional properties when either
(a) the target class referenced by the
@TargetNode
is a base class with inheriting classes,(b) or the target class has a back reference to the source node.
Both conditions lead to corrupted data when the second relation is stored to the same target node. The diagram below shows the case how data model below should be stored in the database:
![image](https://private-user-images.githubusercontent.com/519754/332945895-278261f0-6971-42df-b505-e1d6e8e04b49.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk3ODY4ODksIm5iZiI6MTcxOTc4NjU4OSwicGF0aCI6Ii81MTk3NTQvMzMyOTQ1ODk1LTI3ODI2MWYwLTY5NzEtNDJkZi1iNTA1LWUxZDZlOGUwNGI0OS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjMwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYzMFQyMjI5NDlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT04OWU3YjQ2NTJiYjZmN2I5OWMyNTQ3ZGQ4MzFjMWMzNGYzNDAzY2UwNDMzZWExYzVjYmZiZTc2NjMxZjUwMDhhJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.RajUnSzf6EO6NiD_4xRYOcdkeHsi21bPvbO5yGyZfEo)
This is a simplified set of classes that represents the problem while the actual code is a bit more complex. Also did we remove additional annotations for Lombok away to avoid cluttering the code:
The following simple testcode help reproducing the problem:
The above code only created the correct graph if either the property BugTargetBase in the relationship class is pointing to one of the deriving concrete classes, or if the reverse property relatedBugs in class
BugTargetBase
is deleted. Otherwise the second save operation creates the following graph where only the last saved relation exists and not all three relations as it would be expected.We are using Spring Boot 3.2.1 with the corresponding starter packages but we could also reproduce the behavior with
spring-data-neo4j
version 7.3.0.Question is if that is a bug or how this could be modeled so that we have relationships with properties pointing to nodes that are also pointing back to the other side of the relation.
The text was updated successfully, but these errors were encountered: