-
Notifications
You must be signed in to change notification settings - Fork 132
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
Entities without @ID fail to insert and count #672
Comments
Paging @schauder. Generally, I think that would work. Your case seems to describe an entity with a composite primary key that isn't supported properly yet. |
If one looks at it from a single entity point of view, I agree, it should be considered a single entity with a multi column id. If one takes the Spring Data JDBC perspective the entity should be part of an aggregate, with a unique key consisting of the back reference to the root and all values, which in this case is just a single value pointing to the other aggregate. If someone would find the time to implement multipart ids, that would be highly appreciated. |
Thanks @mp911de and @schauder for the feedback. I tried to add a little more details of my issue to the description. With regards to the insert issue it generally works, but fails when the database returns the inserted rows. If you add this test case to the R2dbcEntityTemplateUnitTests you will be able to reproduce it.
Please let me know your thoughts. Thanks, Mario. |
That issue was fixed with #711 since version |
I have a Many-To-Many relation entity that fails to insert and count because R2dbcEntityTemplate requires a mandatory idProperty.
I came to this issue while trying to workaround the lack of a Multi Id / Composite Id feature. The solution I found was have no @id annotation and rely on the high flexibility provided by R2dbcEntityTemplate to create my repository (which was very easy by the way, as you can see here).
The limitation I found was that part of the R2dbcEntityTemplate implementation forces a required idProperty with no reason for that during the insert and count operations. Please see bellow the details:
Insert Failure
As I'm using Postgres, all the insert statements have a "RETURNING" clause appended to the operation. When there is no ID, it appends "RETURNING *". With these data being returned back during the insert operation the entity template tries to
populateIdIfNecessary
, but instead of just ignoring it because it's not necessary, it fails complaining the required idProperty. In the way I see, MappingR2dbcConverter could simply skip populateIdIfNecessary when the idProperty is null:Count Failure
During the
doCount
operation R2dbcEntityTemplate submits aFunction.count()
to the projection and it fails because it requires the idProperty to be counted. The same issue supposed to happen withdoExists
operation, but the idProperty was already made optional there using a "*" field instead. I guess the same could be applied here by projecting acount(*)
when there is no idProperty, like this:If you want to, I can submit a PR with the fixes and a couple test cases.
Please let me know your thoughts.
Thanks, Mario.
The text was updated successfully, but these errors were encountered: