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
Quote:
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..
Quote:
SELECT user_id , SUM(odds_won) FROM user_bet_competition_history group by user_id ;
Quote:
Query query = session.createQuery( "select user , SUM(ODDS_WON) from UserBetCompetitionHistory as compHist" ) ;
but get..
Quote:
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
Quote:
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.
I realise that the SUM does not work becasue the query is not returning UserBetCompetitionHistory objects. Can anyone help me by telling me why an arraylist of User objects is being returned and hopefully can anyone help me to get the SUM working?
Thanks.
Hibernate version: 3.0