67,512
社区成员
发帖
与我相关
我的任务
分享
String hql = "select new News(n.newsId,n.newsTitle,n.newsTime,n.newsPic) from News n order by n.newsTime desc";
org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [model.News] [select new News(n.newsId,n.newsTitle,n.newsTime,n.newsPic) from model.News n order by n.newsTime desc]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:258)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)
at dao.NewsDaoImpl.getNewsList(NewsDaoImpl.java:32)
at service.NewsServiceImpl.getNewsList(NewsServiceImpl.java:23)
at action.NewsAction.execute(NewsAction.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:870)
package model;
import java.sql.Timestamp;
/**
* News entity. @author MyEclipse Persistence Tools
*/
public class News implements java.io.Serializable {
// Fields
private Integer newsId;
private String newsTitle;
private Timestamp newsTime;
private Integer newsEditorId;
private String newsEditor;
private Integer newsPic;
private String newsContent;
// Constructors
/** default constructor */
public News() {
}
//id,標題,圖片
public News(Integer newsId, String newsTitle, Integer newsPic) {
this.newsId = newsId;
this.newsTitle = newsTitle;
this.newsPic = newsPic;
}
//id,標題,時間,圖片
public News(Integer newsId, String newsTitle, Timestamp newsTime,
Integer newsPic) {
this.newsId = newsId;
this.newsTitle = newsTitle;
this.newsTime = newsTime;
this.newsPic = newsPic;
}
/** full constructor */
public News(String newsTitle, Timestamp newsTime, Integer newsEditorId, String newsEditor, Integer newsPic, String newsContent) {
this.newsTitle = newsTitle;
this.newsTime = newsTime;
this.newsEditorId = newsEditorId;
this.newsEditor = newsEditor;
this.newsPic = newsPic;
this.newsContent = newsContent;
}
// Property accessors
public Integer getNewsId() {
return this.newsId;
}
public void setNewsId(Integer newsId) {
this.newsId = newsId;
}
public String getNewsTitle() {
return this.newsTitle;
}
public void setNewsTitle(String newsTitle) {
this.newsTitle = newsTitle;
}
public Timestamp getNewsTime() {
return this.newsTime;
}
public void setNewsTime(Timestamp newsTime) {
this.newsTime = newsTime;
}
public Integer getNewsEditorId() {
return this.newsEditorId;
}
public void setNewsEditorId(Integer newsEditorId) {
this.newsEditorId = newsEditorId;
}
public String getNewsEditor() {
return this.newsEditor;
}
public void setNewsEditor(String newsEditor) {
this.newsEditor = newsEditor;
}
public Integer getNewsPic() {
return this.newsPic;
}
public void setNewsPic(Integer newsPic) {
this.newsPic = newsPic;
}
public String getNewsContent() {
return this.newsContent;
}
public void setNewsContent(String newsContent) {
this.newsContent = newsContent;
}
}
String hql = "select newsId,newsTitle,newsTime,newsPic from News order by newsTime desc";
List<Object[]> list = session.createQuery(hql)
.setFirstResult(fristResult).setMaxResults(maxResult)
.list();
newsList = new ArrayList<News>();
for (Object[] object : list) {
News n = new News();
n.setNewsId((Integer) object[0]);
n.setNewsTitle((String) object[1]);
n.setNewsTime((Timestamp) object[2]);
n.setNewsPic((Integer) object[3]);
newsList.add(n);
}
但,原来的那个为啥不能用,还是不知道。。。不甘心啊