你在hibernate.cfg.xml里配置把sql打印出来放到Mysql里执行一下不就知道了。Column 'id0_0_' not found

解决方案 »

  1.   

    谢谢。不过我是新手,我还是搞不明白怎么办,现在吧配置文件贴出来,请再帮忙回复以下。谢谢!*.hbm.xml如下:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="model">
    <class
    name="Student"
    table="student"
    >
    <meta attribute="sync-DAO">false</meta>
    <id
    name="Id"
    type="string"
    column="id"
    >
    <generator class="uuid.hex"/>
    </id> <property
    name="Name"
    column="Name"
    type="string"
    not-null="true"
    length="10"
    />
    <property
    name="Age"
    column="Age"
    type="java.lang.Byte"
    not-null="false"
    length="4"
    />
    </class>
    <sql-query callable="true" name="getAllInfo">
    <return alias="student" class="model.Student">

    <return-property name="Name"
    column="Name"></return-property>

    <return-property name="Age"
    column="Age"></return-property>
    </return>
    {CALL GetAllinfo()}
    </sql-query>
    </hibernate-mapping>
    *.cfg.xml如下:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration
        PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>
        <session-factory > <!-- local connection properties -->
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/schoolproject</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">800613</property>
    <!-- property name="hibernate.connection.pool_size"></property --> <!-- dialect for MySQL -->
            <property name="dialect">org.hibernate.dialect.MySQLDialect</property>        <property name="hibernate.show_sql">true</property>
            <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <mapping resource="model/Student.hbm.xml"/>
        </session-factory>
    </hibernate-configuration>*.java如下
    package testhibernate;import java.util.List;import org.hibernate.*;
    import org.hibernate.cfg.*;
    import org.hibernate.classic.Session;import model.Student;public class TestHibernate { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO 自动生成方法存根 try{
    SessionFactory sf = new Configuration().configure().buildSessionFactory();
    Session session = sf.openSession();
    // Transaction tx = session.beginTransaction();

    Query query = session.getNamedQuery("getAllInfo");
    List su = query.list();

    for (int i=0;i<su.size();i++){
    Student st = (Student) su.get(i);
    // st.setName("学生"+i);
    // st.setAge("22");
    // session.save(st);
    System.out.println(st.getName()+"\t"+st.getAge());
    }
    // tx.commit();
    session.close();
    System.out.println("数据chaxun成功");
    }catch(HibernateException e){
    e.printStackTrace();
    }
    }}
      

  2.   

    org.hibernate.exception.SQLGrammarException,SQL语句错啦,你的存储过程中有错误,检查一下吧