-->
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.  [ 1 post ] 
Author Message
 Post subject: Why I get a "Unable to locate appropriate constructor ..."?
PostPosted: Mon Apr 26, 2010 8:18 pm 
Regular
Regular

Joined: Tue Feb 17, 2009 3:36 pm
Posts: 78
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.


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

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.