Joe Carbonella
Joe Carbonella

Reputation: 51

play framework ebean RawSql paging

Should it be possible to use Paging with a custom SQL ebean query? For example, when I set up this query:

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

...I can then call...

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

...without any problems (i.e. I get back a valid List of salesPipelineRow objects). However, when I instead try something like...

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

...I get a null error such as:

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

Can anyone explain why the FROM, WHERE and GROUP BY clauses are getting replaced by "null"?

Thanks!

Upvotes: 2

Views: 2138

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220852

I guess this would have to be run through the EBean mailing lists (if it is still active. I think EBean is quite dead). Looks like a bug to me. The SQL that should be rendered would be:

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

Upvotes: 0

Related Questions