英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论