Michał Maliszewski (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ad7619...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNTRmMzIyYTBj...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16859?atlOrigin=eyJpIjoiNTRmMz...
) HHH-16859 (
https://hibernate.atlassian.net/browse/HHH-16859?atlOrigin=eyJpIjoiNTRmMz...
) max() doesn't work with Enums (
https://hibernate.atlassian.net/browse/HHH-16859?atlOrigin=eyJpIjoiNTRmMz...
)
Change By: Michał Maliszewski (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ad7619...
)
Assuming we have the following entity:
{code:java}@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;
// ...
}{code}
and the following Data Access Object with a Query:
{code:java}@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();
}{code}
would provide to the following exception:
{noformat}org.hibernate.QueryException: Parameter 1 of function max() has type
COMPARABLE,
but argument is of type com.some.enum.ESomeEnum{noformat}
This is a bit unpleasant as it was working well with Hibernate 5.6.x and still usage of:
{code:java} @Query("select s from SomeDbo s where s.type = 1")
List<SomeDbo> findSomeOfTypeOne();{code}
works fine in Hibernate 6.2.5. The possible workaround I see for now is by doing:
{ noformat code:java } @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();{ noformat code }
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.atlass...].
(
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 )