I'm using the latest version of JBoss (4.2.0GA, that one is bundled with Hibernate EntityManager 3.2.1.GA, Hibernate Annotations 3.2.1.GA, Hibernate 3.2.3) and I'm trying to use the "NEW" HQL operator. My query is:
Code:
SELECT NEW mypackage.ReportEntry(a.name,ca.name,cl.date,COUNT(*)) FROM Click cl JOIN cl.campaign ca JOIN ca.agency a WHERE a.name=:aname GROUP BY a.name,ca.name,cl.date
It fails execution with this error message:
Code:
org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [mypackage.ReportEntry] [SELECT NEW mypackage.ReportEntry(a.name,ca.name,cl.date,COUNT(*)) FROM mypackage.Click cl JOIN cl.campaign ca JOIN ca.agency a WHERE a.name=:aname GROUP BY a.name,ca.name,cl.date]
That's strange, because the somepackage.ReportEntry class has this constructor:
Code:
public ReportEntry(String aName, String caName, java.sql.Date date, Long count) {
super();
...
}
I've tried retriving the type of the four elements retrieved by the query by executing the query without the NEW operator:
Code:
SELECT a.name,ca.name,cl.date,COUNT(*) FROM Click cl JOIN cl.campaign ca JOIN ca.agency a WHERE a.name=:aname GROUP BY a.name,ca.name,cl.date
and looking at the classes of the elements in the Object[] returned for each row. It says
Code:
java.lang.String
java.lang.String
java.sql.Date
java.lang.Long
These are exactly the types in my constructor. I suspect this is a bug in Hibernate. Can anyone shed light on this issue?
It seems other users have had similar issues although their solutions seems to be identical to mine,which doesn't work:
http://forum.hibernate.org/viewtopic.php?p=2330678
http://forum.hibernate.org/viewtopic.php?p=2343242