使用引用类休眠@OrderBy

Hibernate @OrderBy with referenced class(使用引用类休眠@OrderBy)
本文介绍了使用引用类休眠@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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
How to define composite foreign key mapping in hibernate?(如何在Hibernate中定义复合外键映射?)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)