我有类似的数据库结构。唯一的区别是我在从 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 中获取所有有用内容的列表。
但我收到语法错误。
你能说一下我的例子有什么问题吗?也许您知道达到此目的的更好方法?