java - 我如何告诉 SpringData/Hibernate 我想要我的非唯一结果作为 java 集合?
问题描述
所以我正在开发一个支持本地化的应用程序,所以我的数据库有本地化。我有这个查询(使用@Query 注释):
select new com.fullstack.daos.projections.LocalizedTutorialDAO(t.id, t.created, t.createdBy, t.lastModified, t.lastModifiedBy, t.version, t.exclusive, (VALUE(l)).name, (VALUE(l)).description, tp) from tutorial t join t.localizations l join t.topics tp where (VALUE(l)).name like %:name% and (KEY(l)) = :lang
如果我不包括 t.topics 它工作得很好,但如果我这样做,它会给我:
Caused by: javax.persistence.NonUniqueResultException: query did not return a unique result: 3
事情是,这应该发生,看到 t.topics 是一组代表 @ElementCollection 的字符串。当我执行默认的 findById 时,它会获取它,为什么在这种情况下我的投影不能将所谓的“非唯一结果”转换为它应该是的 Set?
public class LocalizedTutorialDAO {
private UUID id;
private LocalDateTime created;
private String createdBy;
private LocalDateTime lastModified;
private String lastModifiedBy;
private int version;
private String name, description;
private Set<String> topics = new HashSet<>();
public LocalizedTutorialDAO(UUID id, LocalDateTime created, String createdBy, LocalDateTime lastModified,
String lastModifiedBy, int version, boolean exclusive, String name, String description, String topics) {
super(id, created, createdBy, lastModified, lastModifiedBy, version);
this.name = name;
this.description = description;
this.topics = topics;
}
}
解决方案
推荐阅读
- reactjs - React TypeScript:使用 react-router-dom 在路由更改时调用函数
- json - Dart - 按 json 值过滤数组
- excel - 如何根据单元格值将行 x 次复制到另一个工作表中,并创建一个填充特定内容的新列?
- javascript - 控制台记录 sinon.spy() 显示 [Function] 而不是 spy 的内容
- sql - 删除 SQL 中 created_at 的毫秒部分以与其他日期时间进行比较
- string - 转换边缘数据网络失败 X
- video - ffmpeg 参数以使用完全重新编码来剪切视频文件
- css - 如何创建一个间距相等且每行三个项目的产品网格?
- javascript - 如何从 SuperTest 笑话中的所有页面获得响应
- javascript - 由于已声明的“未定义”变量,模态错误