我想搜索这两个不同的变量:
@Enumerated(EnumType.STRING)
@Column(length = 20)
@Convert(converter = WorksEnumConverter.class)
@GenericField(valueBridge = @ValueBridgeRef(type = WorksValueBridge.class))
private WorksEnum works;
@Convert(converter = AcquisitionTypeConverter.class)
@Enumerated(EnumType.STRING)
@Column(length = 10)
@GenericField(valueBridge = @ValueBridgeRef(type = AcquisitionTypeBridge.class))
private AcquisitionTypeEnum acquisitionType;如您所见,有两种类型的Enum,我想使用hibernate搜索通过多个关键字进行搜索,我使用了桥接器和转换器,并且我总是得到不能将字符串转换为枚举的错误--这是hibernate搜索实现的代码:
if (requestSearchCustomer.getKeyword() != null) {
final String[] keywords = requestSearchCustomer.getKeyword().split(",");
final SearchPredicate keywordPredicate = getSearchScope().predicate().terms()
.fields(RequestDB_.WORKS, RequestDB_.ACQUISITION_TYPE)
.matchingAny(keywords).toPredicate();
predicate.must(keywordPredicate);
}发布于 2022-04-11 09:36:06
如果您想传递字符串,而不是Hibernate搜索所期望的枚举类型,则需要禁用Hibernate搜索的自动转换:
if (requestSearchCustomer.getKeyword() != null) {
final String[] keywords = requestSearchCustomer.getKeyword().split(",");
final SearchPredicate keywordPredicate = getSearchScope().predicate().terms()
.fields(RequestDB_.WORKS, RequestDB_.ACQUISITION_TYPE)
.matchingAny(Arrays.asList(keywords), ValueConvert.NO).toPredicate();
predicate.must(keywordPredicate);
}请参阅https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#search-dsl-argument-type
https://stackoverflow.com/questions/71825205
复制相似问题