How to use ENUM value in JPQL

Hi,

I’m using Cuba 7.1.

I want to filter a picker field with a type of records. There is an Enum defined for the type of the record. So how to use the value of an Enum in the JPQL where clause.

Like this?

<loader id="staffsDl">
                <query>
                    <![CDATA[select e from align_Person e where e.personType = PersonType.STAFF]]>
                </query>
            </loader>

PersonType is the enum and STAFF is the one of the enum value. I know i can hard code the value(code) of the STAFF in the where clause and get the desired output.

But i don’t feel that is the right way to do it. Kindly suggest.

Hello.

I think you might need the @enum function.

<loader id="staffsDl">
            <query>
                    <![CDATA[select e from align_Person e where e.personType = @enum(com.whatever.PersonType.STAFF)]]>
           </query>
</loader>

https://doc.cuba-platform.com/manual-7.1/jpql_macro.html

2 Likes

Thanks Ray, It worked!!