67,537
社区成员
发帖
与我相关
我的任务
分享
@Override
public int countAllSubject() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
return ((Long) session.createQuery(
"select count(*) from Post where idParent=0").iterate().next())
.intValue();
}
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
net.java2000.notepad.service.impl.hibernate.PostServiceHibernateImpl.countAllSubject(PostServiceHibernateImpl.java:24)
org.apache.jsp.jsph.index_jsp._jspService(index_jsp.java:93)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
@Override
public int countAllSubject() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Number number=((Number) session.createQuery(
"select count(*) from Post where idParent=0").iterate().next());
return number.intValue();
}
public void countAllSubject() {
this.session = this.sessionFactory.getSessionFactory().openSession();
this.session.beginTransaction();
System.out.println(session.createQuery("select count(*) from User").iterate().next().getClass());
}
public static void main(String args[]) {
BaseDAO b=new BaseDAO();
b.countAllSubject();
}