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.  [ 3 posts ] 
Author Message
 Post subject: HQL- no appropriate constructor
PostPosted: Tue Sep 28, 2010 8:48 pm 
Newbie

Joined: Tue Sep 28, 2010 8:34 pm
Posts: 2
i have a DTO class with the following constructor:

Code:
   public void ListingItem(String tradename,String strength, String unit )
   {
      this.tradeName = tradename;
      this.strength = strength;
      this.unit = unit;
      
   }


I have the following named query in my Listings class:
Code:
@NamedQuery(name = "findDistinctStrengthUnitTradeNameListingsByStrengthContaining", query = "select distinct new com.medtimetable.domain.ListingItem(myListings.tradename, myListings.strength, myListings.unit) from Listings myListings where myListings.tradename like ?1")


The relevant fields in the Listings class are defined as follow:

Code:
   @Column(name = "STRENGTH", length = 10)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String strength;
   /**
    */

   @Column(name = "UNIT", length = 10)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String unit;
   /**
    */

   @Column(name = "TRADENAME", length = 100)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String tradename;


I am getting the following exception:

Quote:
ErrorCounter - Unable to locate appropriate constructor on class [com.medtimetable.domain.ListingItem]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.medtimetable.domain.ListingItem]
2010-09-28 17:39:14,506 ERROR [main] SessionFactoryImpl - Error in named query: findDistinctStrengthUnitTradeNameListingsByStrengthContaining
org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.medtimetable.domain.ListingItem] [select distinct new com.medtimetable.domain.ListingItem(myListings.tradename, myListings.strength, myListings.unit) from com.medtimetable.domain.Listings myListings where myListings.tradename like ?1]
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:238)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:162)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:113)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)





HELP!!!!!!!!!! :)

Thanks,

Shy Kraus


Top
 Profile  
 
 Post subject: Re: HQL- no appropriate constructor
PostPosted: Tue Sep 28, 2010 9:55 pm 
Beginner
Beginner

Joined: Fri Mar 11, 2005 7:46 am
Posts: 29
Kraus - have a look at your code:

Code:
public [b]void[/b] ListingItem(String tradename,String strength, String unit )
   {
      this.tradeName = tradename;
      this.strength = strength;
      this.unit = unit;
     
   }

Notice void? That's why constructor is not found. Remove it and it should work :-)


Top
 Profile  
 
 Post subject: Re: HQL- no appropriate constructor
PostPosted: Wed Sep 29, 2010 12:33 am 
Newbie

Joined: Tue Sep 28, 2010 8:34 pm
Posts: 2
Ooooopppppssss!!!

Thanks Kostaky!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.