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

Querydsl parameter binding problem with @Convert Field #3017

Closed
tj3828 opened this issue Sep 7, 2021 · 1 comment
Closed

Querydsl parameter binding problem with @Convert Field #3017

tj3828 opened this issue Sep 7, 2021 · 1 comment

Comments

@tj3828
Copy link

tj3828 commented Sep 7, 2021

Observed vs. expected behavior

When the field to which @convert is applied is used as a search condition,
if true is returned to the casebuilder statement in select, the @convert is not applied to the parameter in the where statement.

Observed : select case when runsubject0_.Contents_Grade_Cd='' then 1 else 1 end as col_0_0_ from TBL_RUN_SUBJECT runsubject0_ where runsubject0_.Pass_Confirmed_Yn=1

expected behavior : select case when runsubject0_.Contents_Grade_Cd='' then 1 else 1 end as col_0_0_ from TBL_RUN_SUBJECT runsubject0_ where runsubject0_.Pass_Confirmed_Yn='Y'

Steps to reproduce

  • entity field
@Convert(converter = BooleanToYNConverter.class)
@Column(name="Pass_Confirmed_Yn")
private boolean passConfirmedYn;	
  • converter
public class BooleanToYNConverter implements AttributeConverter<Boolean, String> {
	
	@Override
	public String convertToDatabaseColumn(Boolean attribute) {
		return (attribute != null && attribute) ? "Y" : "N";
	}
	
	@Override
	public Boolean convertToEntityAttribute(String s) {
	    return "Y".equals(s);
    }
}
  • Observed sample query
JPAQuery<GovernmentSupportFundEnrollDTO> query = new JPAQuery<>(em);
            query
                .select(
                        Projections.fields(GovernmentSupportFundEnrollDTO.class,
                        new CaseBuilder()
                            .when(runSubject.contentsGradeCd.eq(""))
                                .then(true)
                            .otherwise(false)
                            .as("refundYn"))
                    )
                .from(runSubject)
                .where(runSubject.passConfirmedYn.eq(true))
                .fetch();

result : select case when runsubject0_.Contents_Grade_Cd='' then 1 else 1 end as col_0_0_ from TBL_RUN_SUBJECT runsubject0_ where runsubject0_.Pass_Confirmed_Yn=1

If the sample query does not return true to the case builder, @convert is normally applied.

  • expected behavior sample query
JPAQuery<GovernmentSupportFundEnrollDTO> query = new JPAQuery<>(em);
            query
                .select(
                        Projections.fields(GovernmentSupportFundEnrollDTO.class,
                        new CaseBuilder()
                            .when(runSubject.contentsGradeCd.eq(""))
                                .then(false)
                            .otherwise(false)
                            .as("refundYn"))
                    )
                .from(runSubject)
                .where(runSubject.passConfirmedYn.eq(true))
                .fetch();

result : select case when runsubject0_.Contents_Grade_Cd='' then 1 else 1 end as col_0_0_ from TBL_RUN_SUBJECT runsubject0_ where runsubject0_.Pass_Confirmed_Yn='Y'

Environment

Querydsl version: 4.2.1

Querydsl module: com.querydsl:querydsl-core:4.2.1

Database: mariadb

JDK: 1.8

@tj3828 tj3828 added the bug label Sep 7, 2021
@jwgmeligmeyling
Copy link
Member

See #2652

@querydsl querydsl locked and limited conversation to collaborators Sep 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants