[英]JPA OrderBy in @OneToMany by external field
I have entities:我有实体:
@Entity
public class C {
@Column
private String name;
}
@Entity
public class B {
@Column
private Integer id;
@ManyToOne
@JoinColumn(name = "id_c")
private C c;
}
@Entity
public class A {
@OneToMany(mappedBy = "a")
@OrderBy("id")
private Set<B> itemsB;
}
Now when i access to A.itemsB() - items ordered by B.id现在,当我访问 A.itemsB() - 按 B.id 订购的项目时
I need to get A.itemsB() ordered by C.name.我需要按 C.name 订购 A.itemsB()。 Is this possible?
这可能吗?
I tried to write something like @OrderBy("c.name") but it not work.我试图写一些类似 @OrderBy("c.name") 的东西,但它不起作用。
只需检查导入的 Order : org.hibernate.annotations.OrderBy 或 javax.persistence.OrderBy .. 你应该使用第二个。
您不应使用“Set<B>”,而应使用“List<B>”。集合始终是无序的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.