开发者

HQL IN operator, Array of Enums ClassCastException

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.setParamete开发者_开发百科r("types", types);

I get:

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

Any ideas?


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

This should do it.


query.setParameterList("types", types);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜