【问题标题】:How can I to order an EntityQuery query in a seam app?如何在 seam 应用程序中订购 EntityQuery 查询?
【发布时间】:2010-11-01 22:04:47
【问题描述】:

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

bean 扩展了 EntityQuery。

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

我想在我的 EJBQL 中添加某种“order by”类吗?还是我想通过

设置选择顺序

这是 seam-gen 生成的代码(我已经更改了 RESTRICTIONS,但其他地方都是一样的):

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翻译大致是

select * from office_view where order by office_id

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

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

但我不知道该怎么做,也不知道其中任何一个是否合适。我找不到任何真正解释如何使用这些的文档。

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

或者是否有要添加到我的实体 bean 的注释?还是给构造函数?

选择太多,知识不够。

提前谢谢你。

TDR

【问题讨论】:

  • 第一行的错字。它不是由动作“List”bean 生成的,而是由 seam-gen 和所有其他 bean 生成的。 TDR

标签: seam entity


【解决方案1】:

我最终添加了

setOrderColumn("officeView.officeId");

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

【讨论】:

    【解决方案2】:

    EntityQuery 仅第一次加载限制数组,然后他不再调用限制。 因此,如果您想使用相同的 EntityQuery 对象并更改限制,请使用您的第二个解决方案,我也使用它。或者初始化另一个 EntityQuery 对象并设置不同的限制。

    【讨论】:

      猜你喜欢
      • 2011-01-30
      • 1970-01-01
      • 2011-10-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多