tkaczmarzyk / specification-arg-resolver

An alternative API for filtering data with Spring MVC & Spring Data JPA
Apache License 2.0
658 stars 150 forks source link

Type Mismatch Error for embedded object with generics in ids #262

Open dimitrisLas opened 3 months ago

dimitrisLas commented 3 months ago

Hello,

The specifications result on type mismatch in scenarios like the following: We have 2 entities:

@Entity
class Entity1 (
    var name: String
): IdEntity<Long>()

and

@Entity
@Table
class Entity2(
    @ManyToOne(cascade = [CascadeType.ALL])
    val entity1: Entity1,

    val name: String
): IdEntity<UUID>()

Then using the following endpoint we get a DateTimeParseException even thought the type is long.

@GetMapping
    fun getEntity2(
        pageable: Pageable,
        @And(
            Spec(path="entity1.id", params = ["entity1Id"], onTypeMismatch = OnTypeMismatch.EXCEPTION, spec = Equal::class),
            Spec(path = "name", spec = LikeIgnoreCase::class)
        )
        searchSpecification: Specification<Entity2>?
    ): ResponseEntity<Page<Entity2>> =
        ResponseEntity.ok(entity2Repository.findAll(searchSpecification, pageable))

To reproduce the issue I created the following simple project

The issue can be verified either by: