Cosium / spring-data-jpa-entity-graph

Spring Data JPA extension allowing full dynamic usage of EntityGraph on repositories
MIT License
463 stars 51 forks source link

version 3.2.1 is losing jpa parameters type when using dynamic projections and generics #148

Closed leassis closed 6 months ago

leassis commented 6 months ago

What steps will reproduce the problem ?

Steps to reproduce the behavior:

  1. create a super repository interface using generics

    @NoRepositoryBean
    public interface EntityGraphBaseRepository<T extends EntityId<I>, I extends Serializable> extends EntityGraphJpaRepository<T, I> {
    <X> Optional<X> findById(I id, Class<X> clazz);
    }
  2. create your repository interface extending the your repository```

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



3. then try to use the method
<X> Optional<X> findById(I id, Class<X> clazz);

### What is the expected output ?
a projection of type class<X> should be returned

### What happens instead ?
a exception is thrown
Caused by: org.hibernate.query.SemanticException: Cannot compare left expression of type 'java.lang.Long' with right expression of type 'java.io.Serializable'

### Environment
 - Spring Data JPA version (not the Spring Boot one): 
 3.2.1

 - ORM with version: 
 hibernate 6.4.1

 - spring-data-jpa-entity-graph version: 
 3.2.1

### Link to an automated test demonstrating the problem
https://filetransfer.io/data-package/wF7qTO47#link

### Additional context
Spring boot updated to version 3.2.1 and hibernate 6.4.1, the method org.springframework.data.repository.query.QueryMethod#createParameters(java.lang.reflect.Method) was deprecated in favor of 
org.springframework.data.repository.query.QueryMethod#createParameters(org.springframework.data.repository.query.ParametersSource). The entity graph library is still using the deprecated version, then some metadata information is missed and hibernate type check failing.