日期:2014-05-20  浏览次数:20823 次

Hibernate用Query查询出现的问题
查询语句:
String querySql="select new vo.ContentVO(co.id,co.catalogid,co.title,co.content,co.regardcount,co.replaycount,co.userid,co.parentid,co.createdate,co.replaydate,bu.username) from Bbsuser as bu,Content co where co.catalogid=? and co.userid=bu.id and co.parentid=0 order by co.replaydate desc";


但是查询的时候总是出现异常:
[framework] 2009-04-22 13:32:00,546 - org.hibernate.hql.PARSER -566015 [http-8080-3] ERROR org.hibernate.hql.PARSER - Unable to locate appropriate constructor on class [vo.ContentVO]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: vo.ContentVO]


下面是VO类的构造函数。
public ContentVO(Integer id, Integer catalogid, String title,
String content, Integer regardcount, Integer replaycount,
Integer userid, Integer parentid, java.util.Date createdate, java.util.Date replaydate,
String username) {
this.id = id;
this.catalogid = catalogid;
this.title = title;
this.content = content;
this.regardcount = regardcount;
this.replaycount = replaycount;
this.userid = userid;
this.createdate = createdate;
this.replaydate = replaydate;
this.parentid = parentid;
this.username = username;
}



下面是POJO对象的配置:
<hibernate-mapping>
  <class name="hibernate.pojo.Content" table="content">
  <id name="id" type="java.lang.Integer">
  <column name="id" />
  <generator class="native" />
  </id>
  <property name="catalogid" type="java.lang.Integer">
  <column name="catalogid" not-null="true" />
  </property>
  <property name="title" type="java.lang.String">
  <column name="title" length="45" not-null="true" />
  </property>
  <property name="content" type="java.lang.String">
  <column name="content" length="65535" not-null="true" />
  </property>
  <property name="regardcount" type="java.lang.Integer">
  <column name="regardcount" not-null="true" />
  </property>
  <property name="replaycount" type="java.lang.Integer">
  <column name="replaycount" not-null="true" />
  </property>
  <property name="userid" type="java.lang.Integer">
  <column name="userid" not-null="true" />
  </property>
  <property name="createdate" type="java.util.Date">
  <column name="createdate" length="0" not-null="true" />
  </property>
  <property name="replaydate" type="java.util.Date">
  <column name="replaydate" length="0" not-null="true" />
  </property>
  <property name="parentid" type="java.lang.Integer">
  <column name="parentid" not-null="true" />
  </property>
  </class>
</hibernate-mapping>

------解决方案--------------------
Unable to locate appropriate constructor on class
构造函数不匹配,注意long与Long,int与Integer,java.util.Date.