Skip to content

Conversation

@kfyty
Copy link

@kfyty kfyty commented Dec 15, 2023

When the field alias in SQL is equal to the field name in the class, the property value in the class will be null. This submission has fixed this issue.
eg:
the class:

@Data public class User { @Id private Long id; private Integer fansNum; }

the interface:

@Repository public interface UserRepository extends R2dbcRepository<User, Long> { @Query("select id, fans_num as fansNum from user where id = :id") Mono<User> getById(Long id); }

the query result of getById(id) is: id=1,fansNum = null.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 15, 2023
@schauder
Copy link
Contributor

schauder commented Jan 3, 2024

We expect the selected column to have the proper column name, not the property name, which I think is correct since we are on the database side of things.

Making this more lenient might seem nice at first but might trigger more problems. For example when there are properties propertyname and propertyName and one wants to select only propertyname, then propertyName will get assigned the same value.

While this is a somewhat contrived example I think it demonstrates the conceptual problem of not keeping column names apart.

One could envision some kind of special syntax to make mapping more easy like for example $col(<propertyPath>)$, which could also properly handle embedded entities and similar which currently are kind of difficult to get right.

@kfyty
Copy link
Author

kfyty commented Jan 8, 2024

We expect the selected column to have the proper column name, not the property name, which I think is correct since we are on the database side of things.

Making this more lenient might seem nice at first but might trigger more problems. For example when there are properties propertyname and propertyName and one wants to select only propertyname, then propertyName will get assigned the same value.

While this is a somewhat contrived example I think it demonstrates the conceptual problem of not keeping column names apart.

One could envision some kind of special syntax to make mapping more easy like for example $col(<propertyPath>)$, which could also properly handle embedded entities and similar which currently are kind of difficult to get right.

Okay, but in my unit testing, when there are properties propertyname and propertyName and one wants to select only propertyname, the result of propertyName is null, it will not assigned the same value.

@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 9, 2024
@mp911de
Copy link
Member

mp911de commented Sep 9, 2024

Closing as per #1701 (comment) without merge.

@mp911de mp911de closed this Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

4 participants