oracle 使用引用类休眠 @OrderBy
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1036902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hibernate @OrderBy with referenced class
提问by Mark
I have a class say: "ClassA" which has a collection of "ClassB"
我有一堂课说:“ClassA”,它有一个“ClassB”的集合
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "COLUMN_NAME")
private List<ClassB> lotsOfClasses;
"ClassB" has a mapped class "ClassC" using plain old mapping annotations:
“ClassB”有一个使用普通旧映射注释的映射类“ClassC”:
public class ClassB {
...
@ManyToOne
@JoinColumn(name="AD_POINT_ID")
private ClassC 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 注释添加到ClassA 的集合到ClassB,以便该集合按ClassC 的“名称”属性排序
Like so:
像这样:
@OrderBy(clause="classC.name asc")
All I get are Oracle exceptions saying that classC is unknown.
我得到的只是 Oracle 异常,说 classC 是未知的。
Any help here would be awesome, as its really bugging me at the moment.
这里的任何帮助都会很棒,因为它现在真的让我感到烦恼。
P.S. I should also mention that using the OrderBy annotation on the collection like this: @OrderBy(clause="classC asc") (i.e. without the .name on classC) I get a valid SQL statement, which uses the ID column (the primary key) of classC to order by.
PS 我还应该提到在集合上使用 OrderBy 注释是这样的:@OrderBy(clause="classC asc")(即在 classC 上没有 .name)我得到一个有效的 SQL 语句,它使用 ID 列(主要key) 的 classC 排序。
Cheers, Mark
干杯,马克
回答by ChssPly76
回答by Ji?í Vypěd?ík
use @Sort
with custom comparator instead
@Sort
与自定义比较器一起使用
回答by Atle
回答by Enyra
I only know NHibernate (.NET version), but I guess it should work similar:
我只知道 NHibernate(.NET 版本),但我想它应该类似:
@OrderBy(clause = "name asc")
Or you can try this:
或者你可以试试这个:
@OrderBy("name")