Hi all,
in my DB I have a table mapped with the class Item and there is a column called prezzo that is a String in the java class and a varchar in the DB.
I need an hql query to sum all the values of prezzo. I have tried:
Code:
"SELECT SUM(CAST(item.prezzo AS decimal(12,2))) from Item as item"
but the result is:
Code:
Exception in thread "main" org.springframework.orm.hibernate3.HibernateQueryException: expecting CLOSE, found '(' near line 1, column 40 [SELECT SUM(CAST(item.prezzo AS decimal(12,2))) from skf.model.Item as item]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 40 [SELECT SUM(CAST(item.prezzo AS decimal(12,2))) from skf.model.Item as item]
Then I tried:
Code:
"SELECT SUM(CAST(item.prezzo AS decfloat)) from Item as item"
but the result is:
Code:
Exception in thread "main" java.lang.NullPointerException at org.hibernate.dialect.Dialect$3.getReturnType(Dialect.java:93)
Then I tried:
Code:
"SELECT SUM(CAST(item.prezzo AS double)) from Item as item"
but the result is:
Code:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'double precision)) as col_0_0_ from skf_items item0_' at line 1
Then I tried:
Code:
"SELECT SUM(CAST(CAST(item.prezzo AS decimal(12,2)) AS double)) from Item as item"
but the result is:
Code:
Exception in thread "main" org.springframework.orm.hibernate3.HibernateQueryException: expecting CLOSE, found '(' near line 1, column 44 [SELECT SUM(CAST(CAST(item.prezzo AS decimal(12,2)) AS double)) from skf.model.Item as item]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 44 [SELECT SUM(CAST(CAST(item.prezzo AS decimal(12,2)) AS double)) from skf.model.Item as item]
Then I tried:
Code:
"SELECT SUM(CAST(CAST(item.prezzo AS decfloat) AS double)) from Item as item"
but the result is:
Code:
Exception in thread "main" java.lang.NullPointerException at org.hibernate.dialect.function.CastFunction.render(CastFunction.java:36)
On each case i try to store the result this way:
Code:
List<Double> tots= (List<Double>) hibernateTemplate.find(sql);
I'm getting crazy for this. Can anybody help me please?
Thanks a lot.