开发者

HQL query on map key : Column not found: SQLGrammarException

开发者 https://www.devze.com 2023-01-28 22:09 出处:网络
I have the following model: class A{ Map<String, Integer> tags } class B{ A a; } I need to find instances of B where its associated A has a certain key value in its tags map

I have the following model:

class A{
    Map<String, Integer> tags
}

class B{
   A a;
}

I need to find instances of B where its associated A has a certain key value in its tags map

I issue the following HQL Query

FROM B WHERE index(a.tags) = 'the_value'

Unfortunately, this开发者_如何学Go yields to a SQLGrammarException. The query being built has a WHERE clause that ends with:

and tags2_.tags_idx='the_value'

and the exception message is

Column not found: TAGS2_.TAGS_IDX

Unfortunately, the alias tags2_ is not previously declared in the statement, which leads to the exception.

Any ideas?

Regards


Not sure about the absent alias, but I guess you need the following syntax in this case:

FROM B WHERE 'the_value' IN INDICES(a.tags)

See also:

  • 16.10. Expressions


Can you try something like this?

from B b join b.a a where index(a.tags) = 'the_value'

Or maybe:

from B b where index(b.a.tags) = 'the_value'
0

精彩评论

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