SpringBoot—如何告诉springdata/hibernate我希望将非唯一结果作为java集合?

csbfibhn  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(171)

所以我正在开发一个支持本地化的应用程序,所以我的数据库有本地化功能。我有这个查询(使用@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时,它会获取它,为什么在这种情况下我的投影不能将所谓的“非唯一结果”转换为它应该是的集合?

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

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题