Hello, I've been facing a fatal exception during application startup upon upgrading to Spring Boot 3.2.

The error message is

Failed to create query for method public abstract long com.example.jparepodemo.dao.RelatedToUserJpaRepository.deleteByIdAndUser_Username(java.lang.Object,java.lang.String); Cannot compare left expression of type 'java.lang.Long' with right expression of type 'java.lang.Object'

It seems to be related to using generics in JPA repositories.

Sample Application

Here is a link to a minimal application that reproduces the issue: https://github.com/ryerrappa/spring-data-jpa-generics-issue

There is also a branch in the above repo called working that shows a working application using a previous version of spring boot. Please note in the branch working, the application will still auto-shutdown, however the application starts up successfully.

This issue occurs when using the following:

  • Spring Boot 3.2
  • Hibernate 6.3, 6.4
  • Java 21
  • H2, Postgres

The issue did not occur when using the following:

  • Spring Boot 2.7, 3.0, 3.1
  • Hibernate default dependency versions
  • Java 17
  • H2, Postgres

Code causing issue

please check https://github.com/ryerrappa/spring-data-jpa-generics-issue for a full sample application

RelatedToUserJpaRepository.java

@NoRepositoryBean
public interface RelatedToUserJpaRepository<T, ID> extends JpaRepository<T, ID> {

    Optional<T> findByIdAndUser_Id(ID entityId, UUID userId);

    Optional<T> findByIdAndUser_Username(ID entityId, String userName);

    long deleteByIdAndUser_Id(ID entityId, UUID userId);

    long deleteByIdAndUser_Username(ID entityId, String username);

    boolean existsByIdAndUser_Id(ID entityId, UUID userId);

    boolean existsByIdAndUser_Username(ID entityId, String username);

    boolean existsByUser_Id(UUID id);

    boolean existsByUser_Username(String username);

}

ManyEntitiesToOneUserJpaRepository.java

@NoRepositoryBean
public interface ManyEntitiesToOneUserJpaRepository<T, ID> extends RelatedToUserJpaRepository<T, ID> {

    Page<T> findByUser_Id(UUID id, Pageable pageable);

    Page<T> findByUser_Username(String username, Pageable pageable);

    long countByUser_Id(UUID id);

    long countByUser_Username(String username);
}

StuffRepository.java

public interface StuffRepository extends ManyEntitiesToOneUserJpaRepository<Stuff, Long> {
}

Error message

Failed to create query for method public abstract long com.example.jparepodemo.dao.RelatedToUserJpaRepository.deleteByIdAndUser_Username(java.lang.Object,java.lang.String); Cannot compare left expression of type 'java.lang.Long' with right expression of type 'java.lang.Object'

Comment From: bclozel

This points to a Spring Data JPA concern. Can you create this issue against the Spring Data JPA project?

Thanks!

Comment From: ryerrappa

Will do, thanks for the response

Comment From: Jeeppler

@ryerrappa did you create an issue? If so, can you link it here?

Comment From: ryerrappa

@Jeeppler sure: https://github.com/spring-projects/spring-data-commons/issues/2995

Comment From: ajitsingh-s

Spring data Jpa is not support spring boot 3.2 and java 17. Jpa repository's saveAll() is not supported. It never gives error or any exception. But it can't do the functionality to saveAll() data to the DB.