How can I translate my flexible search query properly for a Java Final String query?

I'm trying to make a webservice on Hybris Commerce to return data from models. My query works for flexible search console, but I have syntax problems with my method in Java.

My flexible search query:

select * from {address as a join customerenvasado as c on {a:owner} = {c:pk}} where {c:rut} like '1754%' 

My error:

{"errors": [{
    "message": "type code 'a: owner' invalid",
    "type": "FlexibleSearchError"
}]}

My function:

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;
}

Upvotes: 2

Views: 3437

Answers (2)

Johannes von Zmuda
Johannes von Zmuda

Reputation: 1822

Your error is here:

"SELECT * FROM {a: " + AddressModel._TYPECODE

Remove the "a:" and it will work.

Upvotes: 1

Arvind Kumar Avinash
Arvind Kumar Avinash

Reputation: 79620

Just change your query as follows and it should work:

SELECT {pk} FROM {Address AS a JOIN customerenvasado AS c ON {a:owner} = {c:pk}} WHERE {c:rut} LIKE '1754%'

In place of the query given above, you can also use the following query:

SELECT {pk} FROM {Address AS a}, {customerenvasado AS c} WHERE {a:owner} = {c:pk} AND {c:rut} LIKE '1754%'

Upvotes: 1

Related Questions