我正在尝试在 Hybris Commerce 上创建一个网络服务来从模型返回数据。我的查询适用于灵活的搜索控制台,但我在 Java 中的方法存在语法问题。
我的灵活搜索查询:
select * from {address as a join customerenvasado as c on {a:owner} = {c:pk}} where {c:rut} like '1754%'
我的错误:
{"errors": [{
"message": "type code 'a: owner' invalid",
"type": "FlexibleSearchError"
}]}
我的职能:
public AddressModel getCustomerEnvasadoForRut(String rut) {
validateParameterNotNull(rut, "Rut must not be null!");
final String querys = "SELECT * FROM {a: " + AddressModel._TYPECODE + " as a join " + CustomerEnvasadoModel._TYPECODE + " as c on {a:owner} = {c:pk}} where {c:rut} like ?ParamRut";
final FlexibleSearchQuery query = new FlexibleSearchQuery(querys);
query.addQueryParameter("ParamRut", rut);
List<AddressModel> result = getFlexibleSearchService().<AddressModel>search(querys).getResult();
if (result != null && !result.isEmpty()) {
return result.get(0);
}
return null;
}
只需按如下方式更改查询,它应该可以工作:
SELECT {pk} FROM {Address AS a JOIN customerenvasado AS c ON {a:owner} = {c:pk}} WHERE {c:rut} LIKE '1754%'
除了上面给出的查询之外,您还可以使用以下查询:
SELECT {pk} FROM {Address AS a}, {customerenvasado AS c} WHERE {a:owner} = {c:pk} AND {c:rut} LIKE '1754%'
你的错误在这里:
"SELECT * FROM {a: " + AddressModel._TYPECODE
删除"a:",它将起作用。