2013-03-11 37 views
2

是否可以使用Paging和自定義SQL ebean查詢?例如,當我成立這個查詢:播放框架ebean RawSql分頁

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」?

謝謝!

+0

我有同樣的問題...你找到一個解決方案? – by0 2013-04-23 05:10:44

回答

0

我想這將不得不通過EBean郵件列表(如果它仍然活躍,我認爲EBean已經死了)。對我來說看起來像一個bug。這應該呈現的SQL是:

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