使用引用类休眠@OrderBy [英] Hibernate @OrderBy with referenced class

查看:35
本文介绍了使用引用类休眠@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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆