L
L
lafayette2012-12-19 16:34:26
Java
lafayette, 2012-12-19 16:34:26

Ebean: Replacing SqlSelect with RawSql

There is this class:

import com.avaje.ebean.annotation.*;
import org.joda.time.LocalDate;

import javax.persistence.Entity;

@Entity
@Sql(select = {
    @SqlSelect(
        name="default",
        query="SELECT DATE(`o`.`date`) AS `date`, COUNT(`o`.`id`) AS `total` FROM `orders` `o` GROUP BY DATE(`o`.`date`)"
    )
})
public class OrdersReport {
  public LocalDate date;

  public Long total;
}


And then there are various queries like:
Ebean.find(OrdersReport.class)
  .where()
  .ge("date", startDate)
  .le("date", endDate);


SqlSelect is marked as deprecated and it is recommended to use RawSql (Ebean.find().setRawSql() ...), which, if I understand correctly, does not allow you to set a query with an annotation.

Any ideas how to write a similar construct with annotations, but without using deprecated classes?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question