Announcement Announcement Module
Collapse
No announcement yet.
Spring Data JPA query method gets results that matching the first characters in field Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data JPA query method gets results that matching the first characters in field

    Hi, I am using Spring Data JPA 1.3.0, I have a repository: CompanyRepository and a service CompanyService.

    This is my problem, I am using the query generated from method name approach in one of my repository methods:

    Code:
    findById_CompanyAndId_NameAndStatus(BigDecimal company, String name, String status);
    And I am calling it from my service like this:

    Code:
    companyRepository.findById_CompanyAndId_NameAndStatus(new BigDecimal(1), "COMP", "A");
    I am expecting the method to return a result only if the three fields are equal to the provided values, it works properly and returns the information for the company when it finds it in the db.

    The problem is that it is also returning the same result when the first characters match, for example the following calls will get the same result:

    Code:
    companyRepository.findById_CompanyAndId_NameAndStatus(new BigDecimal(1), "COMP", "A");
    
    companyRepository.findById_CompanyAndId_NameAndStatus(new BigDecimal(1), "COMPALL", "A");
    
    companyRepository.findById_CompanyAndId_NameAndStatus(new BigDecimal(1), "COMP2", "A");
    second and third should not return any result as they don't exist in the db, but I don't know why they return the same result than the first one that does exist. If I add a character at the beginning then it wont get anything as expected for example:

    Code:
    companyRepository.findById_CompanyAndId_NameAndStatus(new BigDecimal(1), "aCOMP", "A");
    does not return any result because it does not exist, that is correct.

    What can be the problem?
Working...
X