cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

How to find objects by boolean attribute value?

VasiliyRepecki
1-Newbie

How to find objects by boolean attribute value?

Hi.

I defined soft type of WTPart that has global boolean attribute.

I need to find this soft type instances having the attribute=true.

I tried to use code:

long wtPartSoftTypeId;

long globalBooleanAttrId;

QuerySpec querySpec = new QuerySpec(WTPart.class);

int attributeIndex = querySpec.appendClassList(BooleanValue.class, false);

int attrIndices[] = {0, attributeIndex};

querySpec.appendWhere(new SearchCondition(WTPart.class, "thePersistInfo.theObjectIdentifier.id", BooleanValue.class, "theIBAHolderReference.key.id"), attrIndices);

querySpec.appendAnd();

querySpec.appendWhere(new SearchCondition(BooleanValue.class, "definitionReference.key.id", SearchCondition.EQUAL, globalBooleanAttrId), new int[]{attributeIndex});

querySpec.appendAnd();

querySpec.appendWhere(new SearchCondition(BooleanValue.class, BooleanValue.VALUE, SearchCondition.EQUAL, true), new int[]{attributeIndex});

querySpec.appendAnd();

CompositeWhereExpression where = new CompositeWhereExpression(LogicalOperator.AND);

where.append(new SearchCondition(WTPart.class, "typeDefinitionReference.key.branchId", SearchCondition.EQUAL, wtPartSoftTypeId), new int[] {0});

querySpec.appendWhere(where, new int[]{0});

QueryResult queryResult = PersistenceHelper.manager.find((StatementSpec) querySpec);

result query spec looks like:

SELECT A0.*

FROM wt.part.WTPart A0,wt.iba.value.BooleanValue A1

WHERE (A0.idA2A2 = A1.idA3A4) AND (A1.idA3A6 = 289061) AND (A1.value = N'?') AND ((A0.branchIdA2typeDefinitionRefe = 189491))

joins=null

useBind=true [289061, ?, 189491]

And i have an error: A persistence error occurred

The similar code for StringValue attribute works fine.

Can anyone help me?

1 ACCEPTED SOLUTION

Accepted Solutions

Try this for the booleanvalue.

new SearchCondition(BooleanValue.class, BooleanValue.VALUE, SearchCondition.IS_TRUE)

View solution in original post

1 REPLY 1

Try this for the booleanvalue.

new SearchCondition(BooleanValue.class, BooleanValue.VALUE, SearchCondition.IS_TRUE)

Top Tags