Skip to content
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

field value is null when alias are equals to property name #1701

Closed
wants to merge 1 commit into from

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants