Skip to content

Subsequent call to a previouly successful request result to a InvalidDataAccessApiUsageException #2479

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
fistons opened this issue Apr 1, 2022 · 3 comments
Assignees
Labels
status: duplicate A duplicate of another issue

Comments

@fistons
Copy link

fistons commented Apr 1, 2022

Java version: Oracle OpenJDK 17.0.1
Spring Boot version: 2.6.6

I have a very simple repository to list my entities by name starting with a prefix:

package org.example.issue.repository;

import org.example.issue.entity.MyEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MyEntityRepository extends JpaRepository<MyEntity, Long> {

  List<MyEntity> findByNameStartsWith(String namePrefix);
}

And a very simple service calling it :

package org.example.issue.service;

import org.example.issue.entity.MyEntity;
import org.example.issue.repository.MyEntityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MyEntityService {

  private final MyEntityRepository repository;

  @Autowired
  public MyEntityService(MyEntityRepository repository) {
    this.repository = repository;
  }

  public List<String> getSimilarEntitiesName(String prefix) {
    List<MyEntity> similarEntities = this.repository.findByNameStartsWith(prefix);

    return similarEntities.stream()
        .map(MyEntity::getName)
        .collect(Collectors.toList());
  }
}

The first call to getSimilarEntitiesName(String name) works as expected, but each subsequent calls give me an exception: org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [\] did not match expected type [java.lang.String (n/a)]

Weirdly enough, when I add @Param in my repository's method's argument everything works fine:

package org.example.issue.repository;

import org.example.issue.entity.MyEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MyEntityRepository extends JpaRepository<MyEntity, Long> {

  // This works!
  List<MyEntity> findByNameStartsWith(@Param("namePrefix") String namePrefix);
}

Here is a complete sample project: spring-data-jpa-issue.zip

@antoniosanct
Copy link

Impressive! The same with 'Containing' keyword.

@creatorKoo
Copy link

creatorKoo commented Apr 2, 2022

I have same issue.
OpenJDK 11 with spring boot 2.6.6.
And of course jpa with "startsWith".

I think this is a critical issue. I hope it gets fixed VERY soon.

And thanks @fistons to give me work-around solution!

@fistons
Copy link
Author

fistons commented Apr 3, 2022

Looks like a duplicate of #2472

@fistons fistons closed this as completed Apr 3, 2022
@gregturn gregturn added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels May 3, 2022
@gregturn gregturn self-assigned this May 3, 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

5 participants