如何在接缝应用程序中订购EntityQuery查询? [英] How can I to order an EntityQuery query in a seam app?

查看:237
本文介绍了如何在接缝应用程序中订购EntityQuery查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目最初是由seam-gen和动作 List bean生成的,OfficeViewList看起来很像第一次生成时的样子。

My project was originally generated by seam-gen and the action "List" bean, OfficeViewList looks pretty much like it did when first generated.

该bean扩展了EntityQuery

The bean extends EntityQuery.

现在我要订购结果。最好的方法是什么?

Now I want to order the results. What is the best way to do this?

是否要在EJBQL中添加某种 order by类?还是我想通过

Do I want to add some kind of "order by" class to my EJBQL? Or do I want to set the select order via

设置选择顺序?这是seam-gen生成的代码(我更改了 RESTRICTIONS,但在其他方面是相同的):

Here is the code that seam-gen generated (I have changed the RESTRICTIONS, but otherwise it's the same):

private static final String EJBQL = 
        "select officeView from OfficeView officeView";

private static final String[] RESTRICTIONS = {
  "lower(officeView.addr1) like concat(lower(#{officeViewList.officeView.addr1}),'%')",
  "lower(officeView.buildingId) like  
     concat(lower({officeViewList.officeView.buildingId}),'%')",
  "lower(officeView.circuitId) like 
     concat('%',lower({officeViewList.officeView.circuitId}),'%')",};


public OfficeViewList() {
  setEjbql(EJBQL);
  setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
  setMaxResults(25);
}

SQL翻译大致是


从office_view中选择*,其中按office_id排序

select * from office_view where order by office_id

我在考虑使用setOrder或setOrderColumn ,像这样

I was thinking to use setOrder or setOrderColumn, like this

public OfficeViewList() {
  setEjbql(EJBQL);
  setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
  setOrderColumn("office_id"); 
  setMaxResults(25);
}

但我不太清楚该怎么做或是否这些是适当的。我找不到任何真正说明如何使用它们的文档。

but I can't quite figure out how to do it or whether either of these are appropriate. I can't find any documentation that really explains how to use these.

或者我是否在EJBQL语句中添加某种 order by子句?

Or do I add some kind of "order by" clause to by EJBQL statement?

还是在我的实体bean中添加了注释?

Or is there an annotation to add to my entity bean? or to the constructor?

选择太多,知识不足。

请先谢谢您。

TDR

推荐答案

我最终添加了

setOrderColumn("officeView.officeId");

到构造函数,这正是我想要的。

to the constructor and that did exactly what I wanted.

这篇关于如何在接缝应用程序中订购EntityQuery查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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