标准在hibernate中按子类排序

时间:2013-08-06 19:46:48

标签: java hibernate criteria-api

riteria crit = sessionFactory.getCurrentSession()
                .createCriteria(Order.class)
                .setProjection(Projections.distinct(
                    Projections.projectionList()
                    .add(Projections.property("this.id"))
                    .add(Projections.property("this.creationDate"))
                    .add(Projections.property("this.effectiveDate"))
                    .add(Projections.property("this.modificationDate"))))
                .createAlias("this.consultation", "c")
                .createAlias("c.institution", "institution")

我正在尝试使用order.consultation.institution。可能吗? 要做到这一点......

crit.addOrder(org.hibernate.criterion.Order.desc("institution"));

如果我想要其他子类我想访问(多级)。例如,如果我有类似对象A的内容,则包含对象B包含对象C等。因此,A-> B-> C。

1 个答案:

答案 0 :(得分:0)

.createAlias("this.consultation", "c")
.setProjection(Projections.distinct(
Projections.projectionList()
.add(Projections.property("this.id"))
.add(Projections.property("this.creationDate"))
.add(Projections.property("c.institution"))

...

crit.addOrder(org.hibernate.criterion.Order.desc("c.institution"));

对于第二个问题,您可以通过这样做来访问您的子类及其方法(例如A-> B-> C)

.createAlias("this.a", "a")
.createAlias("a.b", "b")
.createAlias("b.c", "c")

等等..