Specification using enum values does not follow @Enumerated(EnumType.STRING)
and tries to convert it to smallint
#3486
Labels
status: waiting-for-feedback
We need additional information before we can continue
status: waiting-for-triage
An issue we've not yet triaged
I have been migrating some services from Spring Boot 2.7.18 to Spring Boot 3.2.5 and after it, I am facing a specific issue with an enum column only using the Specification and I think it could be a bug (or I am doing something wrong).
I have an entity with the following field
As the annotation shows, I am storing it as a String in the DB (PostgreSQL) and that works perfectly.
It also works well when fetching the entity by id using normal repository methods.
But when I create a Specification filtering by the enum, like below.
I get an error
ERROR: invalid input syntax for type smallint: "SENT"
In debugging further, it seems that it is trying to convert the value passed
SENT
to a smallint. This is the query generated (some other fields were truncated)org.hibernate.exception.DataException: JDBC exception executing SQL [select prw1_0.id,prw1_0.acceptance_status,prw1_0.client_id from my_table prw1_0 where cast(prw1_0.acceptance_status as smallint)=? and cast(prw1_0.acceptance_status as smallint)=? order by prw1_0.received_at desc offset ? rows fetch first ? rows only] [ERROR: invalid input syntax for type smallint: "SENT"] [n/a]
going deeper it seems that in the
SimpleJpaRepository
when building the parameterBindingMap, it is defining thejdbcType
asTyneIntJdbcType
instead of some kind of varchar or string that I would expect based on the@Enumerated(EnumType.STRING)
definition.Now, I am not sure if I need to add some other annotation of metadata to the field, or if the problem is the Hibernate or in the data jpa. I came here as saving and fetching are working so I think the mapping of the field is correct in Hibernate and I only have this problem when trying to use the Specification.
I also forced the latest version
3.3.0
of the library and I still see the problem. Also, tried to force a column definition@Column(nullable = false, columnDefinition = "varchar(255)")
but it didn't help.Anything I can do? Any help is really appreciated! Thank you!
The text was updated successfully, but these errors were encountered: