-
Notifications
You must be signed in to change notification settings - Fork 39
Description
The hibernate docs suggest using helper methods to ensure proper synchronization of bi-directional associations (relations).
However, the current v2 development branch does not define any helper methods.
As a result, the in-memory state of entities is likely to get out of sync with the database.
For example, this already happens here:
FAIRDataPoint/src/main/java/org/fairdatapoint/service/resource/ResourceDefinitionService.java
Line 141 in 9e41bf6
| createDependents(definition, reqDto); |
In this case, because the in memory definition is not updated, the DTO that is returned does not include the related items:
FAIRDataPoint/src/main/java/org/fairdatapoint/service/resource/ResourceDefinitionService.java
Line 148 in 9e41bf6
| return toDTO(definition); |
This has gone unnoticed because these relations were not tested.
A quick-and-dirty workaround for this specific case is to move the refresh() call below the createDependents() call.
However, the fact that a manual refresh() call is necessary suggests that the design is not optimal, and there are probably more places where similar problems can occur.
We can prevent this type of problem by introducing add/remove helper methods to all the relevant entity classes.