Skip to content

QueryCreation with 'Containing' and 'Or' creats different queries during consecutive requests #2480

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
antoniosanct opened this issue Apr 1, 2022 · 3 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@antoniosanct
Copy link

Hi! I've problems using QueryCreation process in Spring Data JPA:

Spring Boot 2.6.5
spring-boot-starter-data-jpa
Hibernate ORM core version 5.6.7.Final
Hibernate Commons Annotations {5.1.2.Final}
Using dialect: org.hibernate.dialect.PostgreSQL10Dialect

public interface MyRepository extends CrudRepository<Entity, EntityId> {
  // This methods runs successfully
  @Query("SELECT e FROM Entity e WHERE e.param1 like %?1% or e.param2 like %?1%")
  List<Entity> findUsingQuery(String term);

  // This methods runs OK at first call, fails at consecutive calls
  // "Parameter value [\\] did not match expected type [java.lang.String (n/a)]"
  List<Entity> findByParam1ContainingOrParam2Containing(String param1, String param2);
}

Obviously, I'm using the first occurence but why fails the second during next consecutive calls?? Check that I'm using only one term at first occurence and reusing the same term at the second occurence:

//  select generatedAlias0 from Entity as generatedAlias0 where ( generatedAlias0.param1 like :param0 escape :param1 )
//    or ( generatedAlias0.param2 like :param2 escape :param3 )
repository.findUsingQuery("term");
//  select generatedAlias0 from Entity as generatedAlias0 where ( generatedAlias0.param1 like :param0 escape :param0 )
//    or ( generatedAlias0.param2 like :param2 escape :param1 )
repository.findByParam1ContainingOrParam2Containing("term","term");

Regards,
Antonio.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 1, 2022
@fistons
Copy link

fistons commented Apr 1, 2022

Looks like my issue: #2479

@fistons
Copy link

fistons commented Apr 1, 2022

As a workaround, I explicitly added @Param in my repository method

@antoniosanct
Copy link
Author

antoniosanct commented Apr 1, 2022

Thanks a lot! I close it as duplicated of #2472 #2479

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants