-
Notifications
You must be signed in to change notification settings - Fork 211
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
Spring Data Repositories: Validate ID type #457
Comments
This is great @mp911de, thanks for the comprehensive list of examples, much appreciated. |
@mp911de The |
FYI: I'm thinking just to provide validation without the quickfix... The quick fix might involve not just changing type declaration annotation or extends/implements parameter type but also likely change signatures of implemented methods etc. |
Basically, yes, there must be at most a single In Cassandra, we support composite primary keys, as embedded properties (https://github.com/spring-projects/spring-data-cassandra/blob/b793c94eed89aa602bc9b55a2cb057b9844c3949/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/convert/SchemaFactoryUnitTests.java#L184-L188) or primary key class (https://github.com/spring-projects/spring-data-cassandra/blob/b793c94eed89aa602bc9b55a2cb057b9844c3949/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/convert/SchemaFactoryUnitTests.java#L157C1-L180) |
@mp911de My understanding is for the Cassandra case that if in the domain class i find a member of type I'm finishing off rewrite recipe for the explicit |
@mp911de Here is the rewrite-spring PR: openrewrite/rewrite-spring#355 Please have a look at the test coverage. If there are more cases you might think of feel free to paste code snippets here or in the PR directly. Note that for now domain id is found by considering only Once the PR is in I'll add a bit of "glue" code in STS to mark the related code with an error. |
This is likely to be affected by the solution to #987 |
@mp911de i have added support for MongoDB id field name. The |
Should be fixed with 73b6c6b |
It would make sense to add validation for Spring Data repository definitions, specifically to check that the declared repository ID type is assignable to (compatible with) the domain type. The validation should affect the repository definition and should be triggered by the presence of a repository declaration.
Consider the following declarations:
The ID type in the entity is
String
while the repositories declareLong
. This code indicates a potential bug.The validation should check whether the repository ID type can be assigned from the entity ID type or vice versa. Entities may declare a primitive type so the validation needs to consider primitive wrapper types, too.
Valid cases
Invalid cases
Advanced cases
Sometimes, entities do not declare an Id type so the validation is not possible. In such a case, the validation should be ignored.
Types annotated with
@NoRepositoryBean
indicate framework types and should not be validated. Their subtypes are (unless annotated with@NoRepositoryBean
) should be validated.We've seen various levels of generics usage. While this is not the most common case, it would make sense to consider these cases for validation.
The text was updated successfully, but these errors were encountered: