Maurice (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5b0057d...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMjZhZGQ5ZDRj...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16585?atlOrigin=eyJpIjoiMjZhZG...
) HHH-16585 (
https://hibernate.atlassian.net/browse/HHH-16585?atlOrigin=eyJpIjoiMjZhZG...
) In hibernate 6 a EnumType is returned as an ordinal instead of the actual enum type (
https://hibernate.atlassian.net/browse/HHH-16585?atlOrigin=eyJpIjoiMjZhZG...
)
Issue Type: Bug Assignee: Unassigned Created: 11/May/2023 03:03 AM Environment: java 17
spring 6
windows 11 Priority: Major Reporter: Maurice (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5b0057d...
)
I have this @Query annotation @Query("SELECT new
DTOs.EntityDTOs.cropvariety.CropVarietyPropagationDetailsDTO(s.cropVariety.id,
cast(s.propagationMethod as Enums.PropagationMethod), s.daysUntilHarvestLongestEstimate,
s.minimumTemperature, s.sowDepth) FROM CropVarietyPropagationDetails s WHERE
s.cropVariety.id IN :idList")
If i don’t explicitly cast s.propagationMethod as Enums.PropagationMethod the following
error is thrown when calling the constructor CropVarietyPropagationDetailsDTO :
java.lang.IllegalStateException: Could not determine appropriate instantiation strategy -
no matching constructor found and one or more arguments did not define alias for
bean-injection
This is because s.propagationMethod is stored as an ordinal enum value in the database.
However in Hibernate 5 this caused no issues. It would automatically convert the ordinal
value to the corresponding Enum type value before injecting it into
CropVarietyPropagationDetailsDTO. So i assume the current behavior can be considered a
bug.
Since hibernate 6 i also can’t use the ordinal value in a @Query jpql query statement
anymore. The following no longer works:
@Query("UPDATE User u SET u.userStatus = 0 WHERE u.userStatus = 1")
Instead i have to define it like this:
@Query("UPDATE User u SET u.userStatus = Enums.UserStatus.OFFLINE WHERE u.userStatus
= Enums.UserStatus.ONLINE")
(
https://hibernate.atlassian.net/browse/HHH-16585#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16585#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:84d3b45 )