How can I to order an EntityQuery query in a seam app?

爱⌒轻易说出口 提交于 2019-12-24 22:20:02

问题


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

The bean extends EntityQuery.

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

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

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);
}

The SQL translation is roughly

select * from office_view where order by office_id

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.

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

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

Too many choices, not enough knowledge.

Thank you in advance.

TDR


回答1:


I ended up adding

setOrderColumn("officeView.officeId");

to the constructor and that did exactly what I wanted.




回答2:


EntityQuery load the restrictions array only the first time, then he doesn't call restrictions anymore. So if you want to use the same EntityQuery object and change the restrictions use your second solution, I use it too. Or initialize another EntityQuery object and and set differents restrictions.



来源:https://stackoverflow.com/questions/977388/how-can-i-to-order-an-entityquery-query-in-a-seam-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!