I have an object(table)
UserBetCompetitionHistory(user_bet_competition_history ), that in turn holds an object called
User and a double value called
ODDS_WON
TO get all my UserBetCompetitionHistory objects I use
Query query = session.createQuery( "from UserBetCompetitionHistory as compHist" ) ;
And that works fine but I want to change it to this (working correctly) mySQL query in..
SELECT user_id , SUM(odds_won) FROM user_bet_competition_history group by user_id ;
Query query = session.createQuery( "select user , SUM(ODDS_WON) from UserBetCompetitionHistory as compHist" ) ;
but get..
java.lang.NullPointerException
at org.hibernate.dialect.Dialect$3.getReturnType(Dialect.java:102)
at org.hibernate.hql.ast.util.SessionFactoryHelper.findFunctionReturnType(SessionFactoryHelper.java:382)
at org.hibernate.hql.ast.tree.AggregateNode.getDataType(AggregateNode.java:21)
at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:143)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:705)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:529)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:645)
But the really weird thing is that if I use this line
Query query = session.createQuery( "select compHist.user from UserBetCompetitionHistory as compHist" ) ;
I get a collection of User objects rather than a collection of UserBetCompetitionHistory objects when I start the HQL query at "from.
Is this normal? Am I doing something wrong?
Can anyone help me to get the SUM working?
Thanks.