gpt4 book ai didi

java - 在 HQL 中查询标量集合

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:40:41 28 4
gpt4 key购买 nike

我有以下类(class):

class User {
String username;
@CollectionOfElements
private Set<String> roles = new HashSet<String>();
[many more things here]
}

我想编写一个 HQL 查询来检索所有用户的用户名和角色。

Query query = session.createQuery("select distinct u.username, u.roles from User u");

但它不起作用,它抛出以下异常:

org.hibernate.QueryException: not an entity [select distinct u.username,u.roles from com.eyeprevent.domain.users.User u]

提示 u.roles 不是实体。

我怎样才能达到我想要的? (查询 where u.roles='arole' 也是可能的,但同样,它不起作用)。

最佳答案

你在找这个吗:

select u.username 
from User u
where :role in elements(u.roles)

关于java - 在 HQL 中查询标量集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3423090/

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