gpt4 book ai didi

hibernate - hql 加入@CollectionTable

转载 作者:行者123 更新时间:2023-12-03 08:20:26 24 4
gpt4 key购买 nike

我有一个域 Service带收藏tags如下:

@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;
}

我要选择 Service s with特别 KEYService.tags .

hql加盟ServiceService.tags如下:
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 querying a collection of non-entites ,我试过如下
"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'))]

我也取得了同样的成绩 using criteria api几个月前。

最佳答案

感谢 JPQL querying a collection of non-entites

以下代码有效!!!

"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')) "

关于hibernate - hql 加入@CollectionTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18657422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com