admin管理员组文章数量:1530517
hibernate报错:
17:30| ERROR | ErrorCounter.java 56| Unable to locate appropriateconstructor on class [entity.NewsBean]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: entity.NewsBean]
原因:
是实体类那里没有这个构造方法,提取什么字段就要这个构造方法。
解决方法:
在实体类里面添加这个构造方法,即可解决问题。
测试类代码:
@Test
public void testSelectMySelf(){
Stringhql="select newNewsBean(n.newsid,n.newstitle,n.author) from NewsBean as n";
Queryquery=session.createQuery(hql);//import org.hibernate.Query
List<NewsBean>list=query.list();
for(NewsBeannewsBean:list){
System.out.println("自定义id:"+newsBean.getNewsid());
System.out.println("自定义newstitle:"+newsBean.getNewstitle());
System.out.println("自定义author:"+newsBean.getAuthor());//通过别名来获取
}
}
NewsBean实体类必须添加构造函数代码,否则报错:
public NewsBean(intnewsid, String newstitle, String author) {
super();
this.newsid = newsid;
this.newstitle = newstitle;
this.author = author;
}
完成后重新运行,即可成功地解决了问题。
本文标签: PropertyNotFoundExceptionHibernateorgconstructorNewsBean
版权声明:本文标题:[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: entity.NewsBean 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1726298458a1064873.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论