Play! Framework does not have group by function. This lack of functionality really starts to irritate me. How do I workaround that? I want byRouteId to group by trip_headsign. Simple raw query would look like:
SELECT *
FROM trips
WHERE route_id = 1070
GROUP BY trip_headsign
This is my Trip.java
@Entity
@Table(name="trips")
public class Trip extends Model {
@Constraints.Required
public String route_id;
@Constraints.Required
public String service_id;
@Id
public String trip_id;
public String trip_headsign;
public String direction_id;
public String block_id;
public String shape_id;
@ManyToOne
@JoinColumn(name="route_id")
public TRoute troute;
public static List<Trip> byRouteId(String route_id) {
List<Trip> trips =
Trip.find
.fetch("troute") // fetch TRoute properties.
.where().like("route_id", route_id)
.findList();
return trips;
}
public static Finder<String, Trip> find = new Finder(
String.class, Trip.class
);
}
You can use a raw SQL query instead by using the createNativeQuery function from the EntityManager class from javax.persistence.