hql加入@CollectionTable [英] hql join @CollectionTable

查看:141
本文介绍了hql加入@CollectionTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个域Service,其集合为tags,如下所示:

I have a domain Service with collection tags as below :

@Entity
public class Service extends AbstractEntity<Long> {
            private static final long serialVersionUID = 9116959642944725990L;

        @ElementCollection(fetch = FetchType.EAGER, targetClass = java.lang.String.class)
        @CollectionTable(name = "service_tags", joinColumns = @JoinColumn(name = "s_id"))
        @Column(name = "tag")
        private Set<String> tags;
    }

我想选择Servicewith特别是Service.tagsKEY.

hqlService连接到Service.tags的情况如下:

hql joining Service to Service.tags is as below :

select s from Service s INNER JOIN s.tags t where s.status=0 and (s.serviceType=9 or t.tag in ('College'))

但是,上面的hql返回了我,但出现以下异常:

Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: cannot dereference scalar collection element: tag [select s from com.zazzercode.domain.Service s INNER JOIN s.tags t where s.status=0 and (s.serviceType=9 or t.tag in ('College')) ]

select s from Service s INNER JOIN s.tags t where s.status=0可以.

看着 JPQL查询非实体集合,我尝试如下

"select s from Service s where s.status=0 and s.priviligedUser.priviligedUserType IN (2,4) and (s.serviceType=9 or (KEY(s.tags)='tag' and (VALUE(s.tags)='College'))"

出现以下异常:

Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: null near line 1, column 188 [select s from com.esewa.server.entity.Service s where s.status=0 and (s.serviceType=9 or (KEY(s.tags)='tag' and (VALUE(s.tags)='College'))]

几个月前,我已经使用标准api 实现了同样的目标.

I have achieved same thing using criteria api some months back.

推荐答案

感谢 JPQL查询非实体集合

"select s from Service s INNER JOIN s.tags t where s.status=0 and and (s.serviceType=9 or  VALUE(s.tags) in ('College')) "

这篇关于hql加入@CollectionTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆