admin管理员组文章数量:1122846
With JPQL how can below query can be done ?
SELECT new foo.bar.MyModel(p.parentId, NVL(p.goodChild.childId, p.children.get(0).childId) ) FROM Parent p
So if the good child is not there, then just get the first child. And if there is no children then obviously null.
@Entity
class Parent {
@Id
Long parentId;
@ManyToOne
@JoinColumn(name = "good_child_id")
Child goodChild;
@OneToMany(mappedBy = "parent")
List<Child> children;
}
@Entity
class Child {
@Id
Long childId;
@ManyToOne
Parent parent;
}
本文标签: one to manyJPQLhow to get top childStack Overflow
版权声明:本文标题:one to many - JPQL - how to get top child - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308556a1933702.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论