Trying to create an object from an HQL query, but just can't figure out what i'm doing wrong.
Query:
String query = "SELECT product.code, SUM(product.price), COUNT(product.code)
from Product AS product
GROUP BY product.code"
(or should I use new MyCustomList(product.code, SUM(... , even though it's not mapped?) Now I want to cast this returned list into a similar object:
class MyCustomList{
public String code;
public BigDecimal price;
public int total;
// Constructor
public MyCustomList(String code, String price, int total){ //...
Retrieving the data:
// This throws ClassCastException
List<MyCustomList> list = MyClass.find(query).fetch();
Using Play framework
I think that the section 15.6. The select clause covers what you're trying to achieve:
In your case, you probably want:
Where
MyCustomList
is not necessarily a mapped entity.I know that this is an old post, but you can also use for HQL:
or this for SQL:
with: