Fail to get correct result with a Query on Enum object
search cancel

Fail to get correct result with a Query on Enum object

book

Article ID: 294192

calendar_today

Updated On:

Products

VMware Tanzu Gemfire

Issue/Introduction

Symptoms:

Queries on partitioned regions that involve an Enum object field may give incorrect results when the relevant domain class implements PdxSerializable.

For example:

gfsh>query --query="select testEnum from /exampleRegion where testEnum.code = 1 " 
Result : true 
startCount : 0 
endCount : 20 
Rows : 0 

NEXT_STEP_NAME : END

 
public enum TestEnum {
	A(1, "AA"), B(2, "BB"), C(3, "CC"), D(4, "DD");

	private int code;
	private String desc;

	private TestEnum(int code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}
}
 
public class TestStatus implements PdxSerializable {
	public TestStatus() {

	}

	public TestStatus(TestEnum testEnum) {
		super();
		this.testEnum = testEnum;
	}
.....
}

 

Environment


Cause

Queries like the above are invalid because the call to testEnum.code involves a static class and method invocation, since Java enum types are implicitly static, which is not supported.

Resolution

To write a query using the value of an Enum object field on a partitioned region, you must use the toString method of the enum object or use a query bind parameter.

For example:

gfsh>query --query="select testEnum from /exampleRegion where testEnum.code.toString() = 1"