Michał Maliszewski (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ad7619...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOGVmMjk5MWUx...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16859?atlOrigin=eyJpIjoiOGVmMj...
) HHH-16859 (
https://hibernate.atlassian.net/browse/HHH-16859?atlOrigin=eyJpIjoiOGVmMj...
) max() doesn't work with Enums (
https://hibernate.atlassian.net/browse/HHH-16859?atlOrigin=eyJpIjoiOGVmMj...
)
Issue Type: Bug Affects Versions: 6.2.5 Assignee: Unassigned Components: query-criteria
Created: 27/Jun/2023 07:21 AM Environment: Spring Data JPA 3.1.1
Hibernate 6.2.5 Priority: Major Reporter: Michał Maliszewski (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ad7619...
)
Assuming we have the following entity:
@Entity
@Table(name = "SOME_TABLE" )
public class SomeDbo {
@Id
@Column(name = "ID" , nullable = false )
private Long id;
@Column(name = "SOME_ENUM" )
@Enumerated(EnumType.ORDINAL)
private ESomeEnum type;
// ...
}
and the following Data Access Object with a Query:
@Repository
@ApplicationScope
public interface SomeDao {
@Query( "select distinct s.id, max(s.type) as mx from SomeDbo s group by s.id order
by mx" )
List< Object []> findSomeMax();
}
would provide to the following exception:
org.hibernate.QueryException: Parameter 1 of function max() has type COMPARABLE,
but argument is of type com.some.enum.ESomeEnum
This is a bit unpleasant as it was working well with Hibernate 5.6.x and still usage of:
@Query( "select s from SomeDbo s where s.type = 1" )
List<SomeDbo> findSomeOfTypeOne();
works fine in Hibernate 6.2.5. The possible workaround I see for now is by doing:
@Query("select distinct s.id, max(cast(s.type as Integer) as mx from SomeDbo s group
by s.id order by mx")
List<Object[]> findSomeMax();
instead, which obviously changed the Object [1] type which needs to be converted in the
code back to ESomeEnum type.
It seems that Enum handling needs improvements, as I see several similar issues, e.g.
https://hibernate.atlassian.net/browse/HHH-16445.
(
https://hibernate.atlassian.net/browse/HHH-16859#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16859#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#100227- sha1:3bc807d )