Skip to content
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

Issues with Spring Data JPA repositores after upgrading to Spring Boot 3.2.0 and Hibernate 6.4. Failed to create query when using generics #38635

Closed
ryerrappa opened this issue Dec 2, 2023 · 5 comments
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid

Comments

@ryerrappa
Copy link

ryerrappa commented Dec 2, 2023

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'

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 2, 2023
@ryerrappa ryerrappa changed the title Issues with Spring Data JPA repositores after upgrading to Spring Boot 3.2.0. Failed to create query when using generics Issues with Spring Data JPA repositores after upgrading to Spring Boot 3.2.0 and Hibernate 6.4. Failed to create query when using generics Dec 2, 2023
@bclozel
Copy link
Member

bclozel commented Dec 2, 2023

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

Thanks!

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2023
@bclozel bclozel added status: invalid An issue that we don't feel is valid for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 2, 2023
@ryerrappa
Copy link
Author

Will do, thanks for the response

@Jeeppler
Copy link

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

@ryerrappa
Copy link
Author

@Jeeppler sure: spring-projects/spring-data-commons#2995

@ajitsingh-s
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

5 participants