-
Notifications
You must be signed in to change notification settings - Fork 195
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
Micronaut Data JDBC problem with bidirectional ONE_TO_MANY relation, doesn't initialize parent reference in all children #1054
Comments
But won't there be infinite loop of parent- > children ->parent-> children? |
Look that the And also take account that, for now, Micronaut creates two instances of the Parent class:
You can see that in the attached image. Look that the The "two instances" issue is not really a problem, and maybe could be optimiced to create just one instance, but this is not really the problem with the |
it is not possible to optimise it to create just one since one is created by you, but in order to provide an |
Yes, and this is not the problem, just a comment to answer @PiotrBaczkowski The issue I want to comment is that when you retrieve the one to many relation, the first child is initialised with a |
yes that behaviour appears to be a bug |
I will look at it |
Thanks a lot 🙏 |
@alejandropg I have fixed the missing parent, but your test tests a bit more:
|
Yes, I'm sorry because I should have alerted you before about I was playing with more things and I had more tests 😓 About the delete and update that you mentioned, delete is ok, but the update, I think that maybe the documentation is not clear because it looks like the cascade update it's certainly supported: https://micronaut-projects.github.io/micronaut-data/latest/guide/#sqlAssociationMapping
Isn't it? Or sure I have not understanding some other point, sorry 😅 So @dstepanov, the update should works or not? By your comment I think that it should but right now it isn't, right? |
I would expect the update to work, you can create a new issue so it's not lost.
It's a problem when you have bi-directional relation and immutable classes, there might be a good idea to allow to map some kind of |
Thanks @dstepanov 👍 Sure, no problem, I will add a new issue with the "update", and will prepare the example code with the correct tests 👌 With the two parent "problem" I'm sure that it's not an easy problem. With Kotlin, we used to create the parent first, passing a mutable list that the parent stores in a List property (the non mutable interface). Then we create the children one by one, passing to them the instance of the parent, and then adding the children to the mutable list. So, the effect for the parent's observer is that the parent is immutable because it can see only the List interface. But I suppose that is not ease to do all this stuff automagically, discovering the constructors, the properties... 😅 |
I'm using Micronaut Data JDBC to map two entities, a parent with children, with bidirectional ONE_TO_MANY relation.
But when I retrieve the parent, one of their children is initialized with
null
reference to the parent. The other children are correctly pointing to the parent.Steps to Reproduce
Entire source code in: https://github.com/alejandropg/micronaut-data-jdbc-demo-one-to-many
Expected Behaviour
When I call
findById
I expect to retrieve the parent with the list of their children and each one of these children pointing to the parent.Actual Behaviour
When you retrieve the parent, one of their children is pointing to a null parent.
Environment Information
Example Application
The text was updated successfully, but these errors were encountered: