小编And*_*sky的帖子

使用 hibernate @Formula 获取集合

我有类似的数据库结构。唯一的区别是我在从 A 到 C 实体的路径上有更多表:

在此输入图像描述

我对该结构有以下映射:

@Entity
@Table(name = "a")
class A {
    @Id
    private int id;

    private String title;

    @ElementCollection(targetClass=String.class)
    @Formula("(select (c.useful_information) from A a " +
            "join B b on a.id = b.a_id " +
            "join C c on b.id = c.b_id " +
            "where a.id = id)")
    private List<String> usefulStuff;
}
Run Code Online (Sandbox Code Playgroud)

我的目标是从实体 A 的表 C 中获取所有有用内容的列表。

但我收到语法错误。

你能说一下我的例子有什么问题吗?也许您知道达到此目的的更好方法?

java spring hibernate jpa

5
推荐指数
1
解决办法
8250
查看次数

标签 统计

hibernate ×1

java ×1

jpa ×1

spring ×1