Pivotal Knowledge Base

Follow

Fail to get correct result with a Query on Enum object

Environment

Pivotal GemFire 8 and above

Symptom

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="selelct 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;
	}
.....
}

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="selelct testEnum from /exampleRegion where testEnum.code.toString() = 1"

Additional Information

For additional information on troubleshooting queries on Enum Objects, see the relevant section in the User's Guide.

Comments

Powered by Zendesk