-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Unable to find constructor when using new class and count(*)
PostPosted: Mon Nov 20, 2006 10:24 pm 
Newbie

Joined: Mon Nov 20, 2006 10:09 pm
Posts: 1
Location: Seattle WA
What type is returned form HQL query using count(*).

This worked in Hibernate 2 versions and I've recently upgraded to 3 and noticed this no longer works.

When using a query that is using the syntax

select new com.foo.Bah(f.name, count(*))
from Foo
Where condition = condition
grouby something

Bah old working constructors don't seem to be recognised anymore which makes me think the type returned from count(*) has changed? if I removed the count(*) from the query, the Bah(string) constructor is found no problem.

Bah(String, int); // doesn't work
Bah(String, Integer); //doesn't work



Hibernate version: Hibernate-Version: 3.2.0.ga

Mapping documents: Snippet


<query name="getStats">

Select new new com.somecompany.db.model.TestStats(testcaseresult.className, count(*), sum(testcaseresult.runTime), testcaseresult.result)
from TestCaseResult as testcaseresult
where testcaseresult.testSuiteRunId = :testSuiteRunId
group by testcaseresult.className, testcaseresult.result
</query>


Full stack trace of any exception that occurs:

Nov 20, 2006 6:16:04 PM org.hibernate.hql.ast.ErrorCounter reportError
SEVERE: Unable to locate appropriate constructor on class [com.bea.test.results.db.model.TestCaseResultsClassStats]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.bea.test.results.db.model.TestCaseResultsClassStats]
Nov 20, 2006 6:16:04 PM org.hibernate.hql.ast.ErrorCounter reportError
SEVERE: Unable to locate appropriate constructor on class [com.bea.test.results.db.model.TestCaseResultsClassStats]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.bea.test.results.db.model.TestCaseResultsClassStats]
Nov 20, 2006 6:16:04 PM org.hibernate.impl.SessionFactoryImpl <init>
SEVERE: Error in named query: getTestCaseResultsClassStats
org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.bea.test.results.db.model.TestCaseResultsClassStats] [
select new com.bea.test.results.db.model.TestCaseResultsClassStats(testcaseresult.className, count(*), sum(testcaseresult.runTime), testcaseresult.result)
from com.bea.test.results.db.model.TestCaseResult as testcaseresult
where testcaseresult.testSuiteRunId = :testSuiteRunId
group by testcaseresult.className, testcaseresult.result
]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:235)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:400)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:351)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1218)
at com.bea.test.results.db.hibernate.SessionFactory.currentSession(SessionFactory.java:49)
at com.bea.test.results.db.TestClient.doStuff(TestClient.java:29)
at com.bea.test.results.db.TestClient.main(TestClient.java:74)
Nov 20, 2006 6:16:04 PM org.hibernate.impl.SessionFactoryImpl <init>
SEVERE: Error in named query: getTestClassResultStats
org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.bea.test.results.db.model.TestCaseResultsClassStats] [
select new com.bea.test.results.db.model.TestCaseResultsClassStats(testcaseresult.className, count(*), sum(testcaseresult.runTime), testcaseresult.result)
from com.bea.test.results.db.model.TestCaseResult as testcaseresult
where testcaseresult.className = :className
and testcaseresult.testSuiteRunId = :testSuiteRunId
group by testcaseresult.className, testcaseresult.result
]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:235)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:400)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:351)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1218)
at com.bea.test.results.db.hibernate.SessionFactory.currentSession(SessionFactory.java:49)
at com.bea.test.results.db.TestClient.doStuff(TestClient.java:29)
at com.bea.test.results.db.TestClient.main(TestClient.java:74)
%%%% Error Creating SessionFactory %%%%
org.hibernate.HibernateException: Errors in named queries: getTestCaseResultsClassStats, getTestClassResultStats
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:364)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1218)
at com.bea.test.results.db.hibernate.SessionFactory.currentSession(SessionFactory.java:49)
at com.bea.test.results.db.TestClient.doStuff(TestClient.java:29)
at com.bea.test.results.db.TestClient.main(TestClient.java:74)
Exception in thread "main" java.lang.NullPointerException
at com.bea.test.results.db.TestClient.doStuff(TestClient.java:30)
at com.bea.test.results.db.TestClient.main(TestClient.java:74)


Name and version of the database you are using: MySql 5


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 21, 2006 4:51 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Did you enable the debug level to see if Query parser outputs any more information.
Another way is to make the constructor something like
public Bah (String, Object)
and try and print out the actual Object that it returns.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 21, 2006 9:39 am 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
According to the Hibernate migration guide for 3.2 (http://www.hibernate.org/250.html), count(*) now returns long.

Curtis ...

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
 Post subject: Re:
PostPosted: Mon Jun 14, 2010 3:41 am 
Newbie

Joined: Mon Jun 14, 2010 3:36 am
Posts: 1
CWitherow wrote:
According to the Hibernate migration guide for 3.2 (http://www.hibernate.org/250.html), count(*) now returns long.

Curtis ...


this was a fantastic solution, thnx for this solution, it worked, i changed my type from short to long and it worked for me !!!!!

one more question, is it compulsory to use pojo class in hibernate query?

eg- my query is :
select new UpdateCountDataBean(count(actionId), pname) from ActivityMaster group by pname

where UpdateCountDataBean is not a POJO. instead if i use a pojo class named "UpdateCount", it works, so is it like tht we have to use pojo compulsorily?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.