欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Unable to locate appropriate constructor on class

程序员文章站 2022-04-12 20:59:22
...
[color=red]org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.lj.core.model.Channel] [select new Channel(c.id, c.name) from com.lj.core.model.Channel c where c.status=1 and c.isIndex=1 and c.type= 1][/color]

在执行下述hql语句的时候出错,
"select new Channel(c.id, c.name) from Channel c where c.status=1 and c.isIndex=1"

原因是在这个hql语句中,使用了new Channel(c.id,c.name).

这样hibernate就会在我们的实体类中找相应的构造函数。
所以要在Channel.java类中建立对应的构造函数:

public Channel(int id, String name)
{
super();
this.id = id;
this.name = name;
}