各位高手  救命啊 !====sql select count(*) from student stu where stu.stu_no ='123' and stu.stu_name ='123'
Hibernate: select count(*) from student stu where stu.stu_no ='123' and stu.stu_name ='123'
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1596)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:112)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1414)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:603)
at com.ctoc.hg.basic.dao.StudentDaoImpl.findStudentCount(StudentDaoImpl.java:69)
at com.ctoc.hg.dao.service.ManageServiceImpl.findStudentCount(ManageServiceImpl.java:13)
at com.ctoc.hg.dao.web.struts.action.LoginAction.execute(LoginAction.java:65)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 列名 stu1_0_ 无效。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.findColumn(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getInt(Unknown Source)
at org.hibernate.type.IntegerType.get(IntegerType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:759)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:292)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
... 26 more
这是什么问题啊!这是hbm文件<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.ctoc.hg.basic.vo.Student" table="student" schema="dbo" catalog="stuManage">
        <id name="stuId" type="integer">
            <column name="stu_id" />
            <generator class="native" />
        </id>
        <property name="stuNo" type="string">
            <column name="stu_no" length="50" not-null="true" />
        </property>
        <property name="stuName" type="string">
            <column name="stu_name" length="50" not-null="true" />
        </property>
        <property name="roleId" type="integer">
            <column name="role_id" not-null="true" />
        </property>
        <property name="sex" type="integer">
            <column name="sex" not-null="true" />
        </property>
        <property name="address" type="string">
            <column name="address" length="50" not-null="true" />
        </property>
    </class>
</hibernate-mapping>
这是vo文件package com.ctoc.hg.basic.vo;/**
 * Student entity. @author MyEclipse Persistence Tools
 */public class Student implements java.io.Serializable { // Fields private Integer stuId;
private String stuNo;
private String stuName;
private Integer roleId;
private Integer sex;
private String address; // Constructors /** default constructor */
public Student() {
} /** full constructor */
public Student(String stuNo, String stuName, Integer roleId, Integer sex,
String address) {
this.stuNo = stuNo;
this.stuName = stuName;
this.roleId = roleId;
this.sex = sex;
this.address = address;
} // Property accessors public Integer getStuId() {
return this.stuId;
} public void setStuId(Integer stuId) {
this.stuId = stuId;
} public String getStuNo() {
return this.stuNo;
} public void setStuNo(String stuNo) {
this.stuNo = stuNo;
} public String getStuName() {
return this.stuName;
} public void setStuName(String stuName) {
this.stuName = stuName;
} public Integer getRoleId() {
return this.roleId;
} public void setRoleId(Integer roleId) {
this.roleId = roleId;
} public Integer getSex() {
return this.sex;
} public void setSex(Integer sex) {
this.sex = sex;
} public String getAddress() {
return this.address;
} public void setAddress(String address) {
this.address = address;
}}
这是dao方法 public int findStudentCount(Student stu) {
System.out.println("method findStudentCount invoked....");
int count = 0;
try {
String sql = "select count(*) from student stu where stu.stu_no ="+ "'" +stu.getStuNo()+ "'" + " and stu.stu_name =" + "'" + stu.getStuName() + "'"; 
Query query = null;
if (s == null || !s.isOpen()) {
s = SessionManager.getInstance().getSession();
session_is_close = true;
}
System.out.println("====sql " + sql);
query = s.createSQLQuery(sql).addEntity("stu", Student.class);
BigDecimal result = (BigDecimal)query.uniqueResult();
System.out.println("=====result=== " + result);
count = result.intValue();
} catch (HibernateException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return count;
}

解决方案 »

  1.   

    Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 列名 stu1_0_ 无效。
      

  2.   


    stu.stuNo='123' and stu.stuName='123'注意 面向对象的
      

  3.   

    createSQLQuery(sql) 里面也要写对象的属性?
      

  4.   

    query = s.createSQLQuery(sql).addEntity("stu", Student.class);改为
    query = s.createSQLQuery(sql);
      

  5.   

    count(*) 映射不到 student的 属性
      

  6.   


     where stu.stu_no ='123' and stu.stu_name ='123'
    这个stu_no也要是对象的属性。用对象管理数据库的
      

  7.   

    Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 列名 stu1_0_ 无效。
      

  8.   

    问题已经解决      自己页面foreach取list时没加$   所以报错了 谢谢各位热心的帮助!