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

The BooleanBuilder created with a NoArg constructor generates a different query from a BooleanBuilder created with an initial Arg constructor. #3644

Open
jaybon1 opened this issue Dec 10, 2023 · 0 comments
Labels

Comments

@jaybon1
Copy link

jaybon1 commented Dec 10, 2023

Observed vs. expected behavior

The BooleanBuilder created with a NoArg constructor generates a different query from a BooleanBuilder created with an initial Arg constructor.

This issue does not always occur and has occurred occasionally when building the project multiple.

Steps to reproduce

The BooleanBuilder created with the initial argument constructor produces the expected query, where all conditions (predicate, createDateAfter, and createDateBefore) are applied:

BooleanBuilder booleanBuilder = new BooleanBuilder(predicate);
booleanBuilder.and(QTempEntity.tempEntity.createDate.after(createDateAfter));
booleanBuilder.and(QTempEntity.tempEntity.createDate.before(createDateBefore));

This would result in a query like:

te1_0.delete_date is null and te1_0.create_date>? and te1_0.create_date<?

On the other hand, the BooleanBuilder created with the no-argument constructor only applies the predicate, and the additional conditions are not correctly applied:

BooleanBuilder booleanBuilder = new BooleanBuilder();
booleanBuilder.and(predicate);
booleanBuilder.and(QTempEntity.tempEntity.createDate.after(createDateAfter));
booleanBuilder.and(QTempEntity.tempEntity.createDate.before(createDateBefore));

This would result in a query like:

te1_0.delete_date is null

The query generated in this case might not be as expected.

Environment

Querydsl version: 5.0.0

Querydsl module:
com.querydsl.core.BooleanBuilder
com.querydsl.core.types.Predicate

Database: H2

JDK: 17

Additional details

Upon reviewing the BooleanBuilder code, it appears that there might be a difference in how the 'predicate' is initialized between the constructor and the 'and' method.

In the constructor:

predicate = (Predicate) ExpressionUtils.extract(initial);

image

However, in the 'and' method:

if (predicate == null) {
    predicate = right;
}

image

Is there a difference between using ExpressionUtils.extract() function and not using it?

@jaybon1 jaybon1 added the bug label Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant