Here is my original HQL:
Code:
select new ItemImage(i,id, i.item, i.sessionId, i.main, v.path) from ItemImage i left join i.versions v where i.item.id = :itemID and v.versionName = :name "
and I get the following error:
Quote:
rg.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.abc.xyz.item.domain.ItemImage] [select new ItemImage(i,id, i.item, i.sessionId, i.main, v.path) from com.vernonwu.vsm.item.domain.ItemImage i left join i.versions v where i.item.id = :itemID and v.versionName = :name ]
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:238)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:162)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:113)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1624)
...
Now, I use another way to get the query without any problem:
Code:
List<?> list = getSession()
.createQuery(
"select i.id as id, i.item as item, i.sessionId as sessionId, i.main as main, v.path as path from ItemImage i left join i.versions v where i.item.id = :itemID and v.versionName = :name ")
.setInteger("itemID", itemID).setString("name", "tiny")
.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
List<ItemImage> ls = new ArrayList(list.size());
for (Iterator<?> itr = list.iterator(); itr.hasNext();) {
Map map = (Map) itr.next();
ls.add(new ItemImage((Integer) map.get("id"), (ItemInfo) map
.get("item"), (String) map.get("sessionId"), (Boolean) map
.get("main"), (String) map.get("path")));
}
which uses the same constructor in the previous HQL. Any differences I can think of is casting between int and Integer, boolean and Boolean. I just can't see any problem with the first HQL.