玩框架ebean RawSql分页

时间:2013-03-11 21:12:29

标签: sql playframework pagination ebean rawsql

是否可以将Paging与自定义SQL ebean查询一起使用?例如,当我设置此查询时:

String sql =
          "SELECT   q.event_id              AS event_id,"
        + "         MIN(q.total_price)      AS price_min, "
        + "         MAX(q.total_price)      AS price_max "
        + "FROM     quote q "
        + "WHERE    q.quote_status_id = 2 "
        + "    AND  q.event_id IS NOT NULL "
        + "GROUP    BY q.event_id";

RawSql rawSql = RawSqlBuilder.unparsed(sql)
        .columnMapping("event_id", "event.id")
        .columnMapping("price_min", "priceMin")
        .columnMapping("price_max", "priceMax")
        .create();

com.avaje.ebean.Query<salesPipelineRow> ebeanQuery = Ebean.find(salesPipelineRow.class);

ebeanQuery.setRawSql(rawSql);

......我可以打电话给...

List<salesPipelineRow> list = ebeanQuery.findList();

...没有任何问题(即我找回了salesPipelineRow对象的有效列表)。但是,当我改为尝试类似的事情时......

Page<salesPipelineRow> page = ebeanQuery.findPagingList(5).getPage(0);

...我收到一个空错误,例如:

java.util.concurrent.ExecutionException: javax.persistence.PersistenceException: 
Query threw SQLException:You have an error in your SQL syntax; check the manual that corresponds to your MySQL     
server version for the right syntax to use near 'null t0
limit 6' at line 2
Bind values:[]

Query was:
select t0.price_min c0, t0.price_max c1, t0.event_id c2
from null t0
limit 6

任何人都可以解释为什么FROM,WHERE和GROUP BY子句被“null”替换?

谢谢!

1 个答案:

答案 0 :(得分:0)

我想这必须通过EBean邮件列表运行(如果它仍处于活动状态。我认为EBean已经死了)。对我来说看起来像个错误。 应该呈现的SQL将是:

select t0.price_min c0, t0.price_max c1, t0.event_id c2
from (
    SELECT [... your raw SQL statement here ...]
) t0
limit 6
相关问题