spring-projects / spring-data-relational

Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
https://spring.io/projects/spring-data-jdbc
Apache License 2.0
764 stars 344 forks source link

Nested structure not persistable that goes beyond a first level of a parent child relationship #1771

Closed rudolfschmidt closed 5 months ago

rudolfschmidt commented 5 months ago

Hey, I thought I did something wrong first, but I noticed that you cannot save children that depend on the children of a aggregate parent.

Scenario: you have a type A that is an aggregate that you want to save. Type A has children of type B and Type B has children of type C. It's possible to save type A with children of type B but children of type C are not saved because data-jdbc expact type C to have a foreign key to type A and IMO that is nonsense.

schauder commented 5 months ago

Could you clarify what "cannot save children" means? Doesn't the data get saved? Or is it a problem with loading it again? Do you get an exception?

This might be a duplicate of #1692 but with the current description it is impossible to tell.

I need either confirmation that this is a duplicate of the issue mentioned above or a reproducer.

rudolfschmidt commented 5 months ago

Cannot save children means that he expects a foreign key to type A and because of that it throws an error. You have to use the foreign key for type B in type C and not for type A.

Do you have any test cases for a nested structure until level 2 or above?

schauder commented 5 months ago

Nothing in Spring Data JDBC checks the existence of a foreign key. Could you please at least post the full stack trace?

schauder commented 5 months ago

I'm interpreting your comment here https://github.com/spring-projects/spring-data-relational/issues/1692#issuecomment-2059298013 as this being another duplicate of #1692