日期:2014-05-19  浏览次数:20630 次

Hibernate 的一个小问题
我写的第一个hibernate程序,helloworld就出错了,不知道为啥,求大神指教~~~

首先附上我的hibernate.cfg.xml 配置:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/hibernate</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>


        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>


        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>


        <mapping resource="HibernateModel/student.hbm.xml"/>

    </session-factory>

</hibernate-configuration>


以及我的student.hbm.xml


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package=HibernateModel">

    <class name="student" >
 <id name="id" >
            <generator class="native"/>
        </id>
        <property name="age"/>
        <property name="name"/>
    </class>
</hibernate-mapping>



以下是测试类:

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

import HibernateModel.student;




public class StudentTest {

private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;

publi