Hibernate @OrderBy with referenced class(使用引用类休眠@OrderBy)
问题描述
我有一个班级说: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;
...
}
如何给ClassA的集合添加@OrderBy注解到ClassB,让集合按照ClassC的name"属性排序
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")
我得到的只是 Oracle 异常,说 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 注释,如下所示:@OrderBy(clause="classC asc")(即没有 classC 上的 .name)我得到一个有效的 SQL 语句,它使用 classC 的 ID 列(主键)进行排序.
干杯,标记
推荐答案
很遗憾,您无法做您想做的事.我在此处回答了类似的问题.
It's unfortunately impossible to do what you want. I've answered a similar question here.
@OrderBy 仅支持集合元素的 direct 属性.
@OrderBy only supports direct properties of the collection elements.
这篇关于使用引用类休眠@OrderBy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用引用类休眠@OrderBy
基础教程推荐
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
