HQL IN operator, Array of Enums ClassCastException

早过忘川 提交于 2019-11-30 21:10:34

问题


Here is my stripped down class and enum.

class A
{
    @Enumerated (value = EnumType.STRING)
    AType type;
}

enum AType
{
    X,Y
}

if I run

query = FROM A a WHERE a.type = :type
query.setParameter("type", AType.X);

All is fine and dandy.

However if I do the following:

AType[] types = new AType[1];
types[0] = AType.X;
query = FROM A a WHERE a.type IN (:types)
query.setParameter("types", types);

I get:

Lcom.src.AType; cannot be cast to java.lang.Enum

If I do:

Enum[] types = new Enum[1];
types[0] = AType.X;
query = FROM A a WHERE a.type IN (:types)
query.setParameter("types", types);

I get:

Ljava.lang.Enum; cannot be cast to java.lang.Enum

Any ideas?


回答1:


query.setParameterList("types", types);
                  ^--

This should do it.




回答2:


query.setParameterList("types", types);



来源:https://stackoverflow.com/questions/5083924/hql-in-operator-array-of-enums-classcastexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!