K.C*_*.C. 7 java hibernate jpa hql map
我尝试了这个hql查询,但是当我在以下查询中使用actProp [:key] =:value时,它会抛出UnsupportedOperationException :
选择映射actionProperties中包含值对x,y或z,y的所有操作:
Query query = getSession().createQuery(
"select a from Action a " +
" join a.actionProperties actProp " +
" where (index(actProp) = :key " +
" and actProp[:key] = :value ) " +
" or (index(actProp) = :key2 " +
" and actProp[:key2] = :value ) ");
Run Code Online (Sandbox Code Playgroud)
例外:
java.lang.UnsupportedOperationException
at org.hibernate.hql.ast.tree.IdentNode.resolveIndex(IdentNode.java:67)
Run Code Online (Sandbox Code Playgroud)
在实体Action中:
@CollectionOfElements(fetch = FetchType.EAGER)
private Map<String, String> actionProperties;
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用Hibernate Criteria,但我不认为这是可能的.
有没有人知道要替换的东西:actProp [:key] =:带有工作代码的值?
经过一些试验和错误,我终于找到了解决方案,这不是那么简单.
Query query = getSession().createQuery(
" from Action a " +
" join a.actionProperties actProp " +
" where( (index(actProp) = :key " +
" and :value in elements(a.actionProperties))" +
" or (index(actProp) = :key2 " +
" and :value in elements(a.actionProperties)) )"
);
Run Code Online (Sandbox Code Playgroud)
因此,为了匹配键我使用了index()
函数并匹配我使用elements()
函数的值.
如果您知道更好的解决方案,请告诉我.
归档时间: |
|
查看次数: |
4460 次 |
最近记录: |