0

I am having issues writing an expression query in apache cayenne to retrieve the records from the database.

My requirement is to retrieve the orders from a table which is created by a particular UserDn, where Order Status is not complete. It is not giving results as expected.

I used the below query, but it is giving results only created by UserDn and ignoring the and expression "Order Status is not complete".

Expression expression = ExpressionFactory.matchExp(SAPOrder.CREATED_BY_USER_DN_PROPERTY,  userDN );
expression.andExp(ExpressionFactory.noMatchExp(SAPOrder.ORDER_STATUS_PROPERTY,  "Completed"));
SelectQuery query = new SelectQuery(SAPOrder.class, expression);
Esoteric Screen Name
  • 6,082
  • 4
  • 29
  • 38

1 Answers1

2

You overlooked the fact that 'andExp' and other similar Expression methods are not modifying the original object and are creating a NEW expression object instead. So all you need to change is this:

expression = 
   expression.andExp(ExpressionFactory.noMatchExp(SAPOrder.ORDER_STATUS_PROPERTY,  "Completed"));
andrus_a
  • 2,528
  • 1
  • 16
  • 10