Hibernate 6.2.6.Final 在使用枚举在最大函数中时出现了 QueryException。

huangapple go评论87阅读模式
英文:

Hibernate 6.2.6.Final QueryException when using enum in max function

问题

我已经从Hibernate 6.1.7.Final迁移到6.2.6.Final(在6.2.0.Final版本中也存在该问题),出现了一些与枚举相关的问题。
我有一个如下的查询,在旧版本中可以工作,但现在失败了:

select datasourceView.id, max(datasourceView.datasourceStatus) as DATASOURCE_STATUS_helper_column, datasourceView.id as ID_helper_column

错误信息是:

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: 函数max()的第一个参数类型为COMPARABLE,但参数的类型为com.xxx.datasource.domain.DatasourceStatus

枚举映射:

@Column(name = "status")
@Enumerated(EnumType.STRING)
private DatasourceStatus datasourceStatus;
英文:

I have migrated from Hibernate 6.1.7.Final to 6.2.6.Final (bug exists also in 6.2.0.Final) and there are some enum related issues.
I have a query as below, that was working in older version, but it is failing now:


select datasourceView.id, max(datasourceView.datasourceStatus) as DATASOURCE_STATUS_helper_column, datasourceView.id as ID_helper_column

The error is:

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: Parameter 1 of function max() has type COMPARABLE, but argument is of type com.xxx.datasource.domain.DatasourceStatus

Enum mapping:


@Column(name = "status")
@Enumerated(EnumType.STRING) 
private DatasourceStatus datasourceStatus;

答案1

得分: 0

我已经通过从@Enumerated切换到@Converter并为枚举创建一个转换器来解决了这个问题。

英文:

I have solved the issue by switching from the @Enumerated to the @Converter and creating a converter for enums.

huangapple
  • 本文由 发表于 2023年7月17日 18:37:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76703636.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定