-
Notifications
You must be signed in to change notification settings - Fork 347
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
Custom RowMapper through bean definition not registering #1006
Comments
Could you explain why you need a custom When you can use the standard query, I would expect that you could use custom constructor instead. |
If there are instances where an aggregate has columns in the database that are complex, such as a json file that is a representation of another object, my options would be:
If I were to choose option 2, I would want the row mapper to also be able to be applied to default methods such as findAll, findById, etc. |
Can't you do the same with a custom conversion for the column/type? |
As my understanding (correct me if I am wrong), if I use reading/writing converters, that would apply to every field with that type in the database, which I do not want. For example: if I had a reading converter that maps a String to a Person Object, wouldn't that try to map every varchar in the database to a Person object? I do not see anywhere in the documentation that specifies a way to register a converter only for a specific table and column. |
This is handled by The writing converter would be applied to every The reading converter would be used for values that are of type In many cases this should do the trick. If you have Does that solve your problem? |
Yes I believe that would solve my immediate problem. However, I still think that it would make sense that if someone registers a custom row mapper, which would apply to all custom repository methods, it should also apply to all other default repository methods for that aggregate. Otherwise, what is the point in having some methods that use that row mapper and some that do not? If a rowmapper is defined for an aggregate, it seems like it should be assumed that the rowmapper will be used for all methods under that aggregate. Also an example that I can think of that could be practical: say I have an enum that is stored in the DB as it's string representation for one table, but it's stored as it's ordinal integer value in another table. The converter would not work in this case, and my only options would be to use a rowmapper or set custom getters and setters. |
Also, do converters work with Lists? For example, if I have a |
When we created the option to use row mappers with Anyway, we'll discuss this internally.
No, they currently don't work with collections, which are handled by special code. |
Sure thing. Thanks for all of the quick responses! |
We finally discussed this internally and decided support for RowMapper registration use in standard methods and part tree methods would be a valid improvement. If you are interested a PR would be welcome. |
Hello @schauder, I'm currently trying to implement this feature. I'm still having some questions that I would love to hear your opinion on. As described above, To solve this, I thought of doing one of the following things:
Thanks in advance for your time and input! |
I agree with you that the second option sounds better. |
I have multiple domain aggregates using default row mappers. However, I have one that needs a custom row mapper. When attempting to register and use a custom row mapper for this certain domain through a bean definition of QueryMappingConfiguration, the row mapper is not used and still defaults to the default entity row mapper.
I created a row mapper class:
as well as registering it in a bean of type
QueryMappingConfiguration
According to the documentation, this should be a valid way of registering a row mapper. I want to avoid using the
@Query
annotation, as I will then have to override all of the existing findAll, findById methods in order to use my row mapper for those methods. Either I am missing something, or there is a bug in bean registration for row mappers.Ideally, custom row mappers should work with methods inherited from extending CrudRepository/PagingAndSortingRepository as well as custom methods. Thanks in advance.
The text was updated successfully, but these errors were encountered: