Search code examples
javaofbiz

findByAnd incompatible types


I'm trying to use method findByAnd.

This is part of my code:

ArrayList<String> orderBy;
orderBy.add("productId");

GenericDelegator delegator = (GenericDelegator) DelegatorFactory.getDelegator("default");
GenericValue product = null;

try {
    product = delegator.findByAnd("Product", UtilMisc.toMap("productName", productName), orderBy, false);
} catch (GenericEntityException e) {
    return Response.serverError().entity(e.toString()).build();
}

In this line

product = delegator.findByAnd("Product", UtilMisc.toMap("productName", productName), orderBy, false);

I get this error:

enter image description here

How to correct it? I don't understand how types can be incompatible in my code.


Solution

  • The reason you are getting this error is because the findByAnd method returns a List of GenericValue objects, each GenericValue represents a row in the Product table. The following code will work:

    List<GenericValue> products = delegator.findByAnd("Product", UtilMisc.toMap("productName", productName), orderBy, false);