Skip to content

Nullable parameter with optional check query regression #2601

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

Closed
therealaleko opened this issue Jul 19, 2022 · 2 comments
Closed

Nullable parameter with optional check query regression #2601

therealaleko opened this issue Jul 19, 2022 · 2 comments
Labels
status: duplicate A duplicate of another issue

Comments

@therealaleko
Copy link

therealaleko commented Jul 19, 2022

In 2.6.x this worked (focus is on the last and clause)

@Query("select distinct t from AgentParticipant p " +
      "join p.transaction t " +
      "where p.agent.id = :agentId " +
      "and t.lifecycleState in :state " +
      "and (  :searchText is null or upper(t.address.street) like %:searchText% or upper(t.address.street2) like %:searchText% or upper(t.address.city) like %:searchText% or t.address.zip like %:searchText% )"
  )
  Page<Transaction> findAllForAgentInLifecycleState(
      @Param("agentId") String agentId,
      @Param("state") Set<TransactionLifecycleState> state,
      @Param("searchText") String searchText,
      Pageable pageable);

In 2.7 it no longer works. It doesn't throw an exception, but rather it returns the incorrect result set.

Workaround is to move the null check at the end of the query like so...

      "join p.transaction t " +
      "where p.agent.id = :agentId " +
      "and t.lifecycleState in :state " +
      "and ( upper(t.address.street) like %:searchText% or upper(t.address.street2) like %:searchText% or upper(t.address.city) like %:searchText% or t.address.zip like %:searchText% or :searchText is null )"
  )

Other passing scenario:

  • If the query does not use LIKE clauses it works . E.G., replace like with equality checks
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 19, 2022
@therealaleko
Copy link
Author

therealaleko commented Jul 19, 2022

here is github repo that reproduces the issue.

https://github.com/therealaleko/spring-things

Just revert the version to any 2.6.x SB version and the test will pass

@schauder
Copy link
Contributor

Duplicate of #2548

@schauder schauder marked this as a duplicate of #2548 Jul 20, 2022
@schauder schauder added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants