[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: entity.NewsBean
来源:互联网 发布:淘宝直通车创意是什么 编辑:程序博客网 时间:2024/06/10 19:52
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;
}
完成后重新运行,即可成功地解决了问题。
- [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: entity.NewsBean
- 错误总结之no appropriate constructor in class
- org.hibernate.InstantiationException: No default constructor for entity
- org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class XXX解决
- org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class xxx
- SpringBoot 集成Kotlin : org.hibernate.InstantiationException: No default constructor for entity: : com.easy.kotlin.entity.People
- org.hibernate.InstantiationException: No default constructor for entity: cn.gov.entity.Book
- hibernate出现:org.hibernate.PropertyNotFoundException: Could not find a getter for id in class
- Hibernate报错:org.hibernate.InstantiationException: No default constructor for entity: ,类在下面
- Hibernate出现org.hibernate.InstantiationException: No default constructor for entity解决方法
- org.hibernate.PropertyNotFoundException: Could not find a getter for titlse in class com.po.Intro
- org.hibernate.PropertyNotFoundException: Could not find a getter for titlse in class com.po.Intro异常
- org.hibernate.PropertyNotFoundException: Could not find a getter for empDeptId in class
- org.hibernate.PropertyNotFoundException Could not find a getter for id in class
- org.hibernate.PropertyNotFoundException: Could not find a getter for id in class com.pb.dao.UserDao
- org.hibernate.PropertyNotFoundException: Could not find a getter for sMarathon in class com.honsto.
- Hibernate异常:Unable to locate appropriate constructor on class
- Hibernate异常:Unable to locate appropriate constructor on class
- 跟我学习SSH框架中的国际化如何实现
- java的堆,栈,静态代码区 详解
- uvm_object的理解
- Android Studio 关联GitHub相关操作
- AbstractQueuedSynchronizer的介绍和原理分析
- [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: entity.NewsBean
- C++运算符重载例子代码
- 10进制数与33进制数的转换
- 【DENUVO】一代天子一代臣,这代好像有点“颓”?
- JVM学习 - 体系结构 内存模型
- Android 图案解锁
- BZOJ3244: [Noi2013]树的计数
- 面向对象介绍
- CPU缓存刷新的误解