问题描述
我有一个类地说:ClassA的有ClassB的
I have a class say: "ClassA" which has a collection of "ClassB"
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "COLUMN_NAME")
private List<ClassB> lotsOfClasses;
ClassB的有一个映射类ClassC使用普通的旧映射的注释:
"ClassB" has a mapped class "ClassC" using plain old mapping annotations:
public class ClassB {
...
@ManyToOne
@JoinColumn(name="AD_POINT_ID")
private ClassC classC;
...
}
我如何添加一个@OrderBy注释ClassA的的集合ClassB的,以便收集,由ClassC的名字属性排序
How do I add an @OrderBy annotation to ClassA's collection to ClassB, so that the collection is ordered by the "name" property of ClassC
像这样:
@OrderBy(clause="classC.name asc")
我得到的是甲骨文例外说classC是未知的。
All I get are Oracle exceptions saying that classC is unknown.
在这里任何帮助将是真棒,因为它真的窃听我的时刻。
Any help here would be awesome, as its really bugging me at the moment.
的 P.S。我还要提到的是使用像这样的集合排序依据注解:
@OrderBy(条款=classC ASC)
(即不会对classC的。名称),我得到一个有效的SQL语句,它使用classC的ID列(主键),通过订购。的
干杯,
马克
推荐答案
这是不幸的是不可能做你想要什么。我已经回答了类似的问题here.
It's unfortunately impossible to do what you want. I've answered a similar question here.
@OrderBy
只支持直接集合元素的属性。
@OrderBy
only supports direct properties of the collection elements.
这篇关于Hibernate的@OrderBy与引用的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!