提问人:dracile 提问时间:11/14/2023 最后编辑:dracile 更新时间:11/14/2023 访问量:60
在springboot中使用查询时出现jdbcMapping错误的枚举值
Enum value giving jdbcMapping error while using query in springboot
问:
我的要求是按 patientId、patientType 和 DeletedAt、DeletedBy、DeletedByUserType 查找条目,这三个应该是 null
我使用了这个查询,但它无法映射 patientType,这是一个 ENUM
错误
"An error occurred during data insertion in An error occurred during data insertion in Cannot invoke \"org.hibernate.metamodel.mapping.JdbcMapping.getJdbcValueBinder()\" because \"jdbcMapping\" is null"
查询
@Transactional
@Query(value="SELECT * FROM tb_patient o WHERE o.patientId = :patientId AND o.patientType = :patientType AND o.deletedAt Is Null AND o.deletedBy Is Null AND o.deletedByUserType Is Null ", nativeQuery = true)
List<PatientInsurance> findCustomQuery(@Param("patientId")String patientId, @Param("patientType")PatientTypeEnum patientType);
Enum 类
public enum PatientTypeEnum {
OPG("OPG"),
OTS("OTS");
private final String code;
PatientTypeEnum(String code) {
this.code = code;
}
public String getCode() {
return code;
}
}
实体类
private class InsuranceEntity{
@Enumerated(EnumType.STRING)
@Column(name = "patientType", length = 3, nullable = false)
private PatientTypeEnum patientType;
}
答:
2赞
JeslynTan
11/14/2023
#1
也许在@Query上试试这个
o.patientType=:#{#patientType?.code()}
而不是 o.patientType = :p atientType
评论