Open StefanSrf opened 2 years ago
It's happening because you already have the id assigned. In this case, we assume that the entity is already persisted. Can you try with the latest RC? I think there was some improvement in the case.
Using the latest RC unfortunately does not help. Generating the childs-id on the database works, but that would be a workaround. In my understanding an existing Id should only be used as an indicator for an already persisted entity when a @GeneratedValue annotation is set on that Id. Do you agree?
You can assign the id manually and persist the entity which I think you should do in this case.
Assigning the id manually and persisting works for the parent entity, but the child entity does not get persisted, i.e. the @Relation-Relation.Cascade.ALL is ignored/not functional. I can of course manually persist the child entity, but what's the point of having a cascade value then?
There are some limitations because we don't have any kind of session compared to Hibernate. The most common use-case is to have IDs assigned or uniquely generated, the cascade works in those cases.
Yes, i know. I think it should also work for the less common use-case of already existing ids. I understand that this is probably not trivial to implement. Currently it's unfortunately not obvious that this scenario is not supported.
Expected Behavior
@Relation with Relation.Cascade.ALL should persist child-relations on save
Actual Behaviour
Only the parent is persisted. The debug-logs indicate that the child-relation is also inserted, but they are not saved on the database.
Steps To Reproduce
Environment Information
Example Application
https://github.com/StefanSrf/micronaut-data-cascade-bug
Version
3.3.4