求助,新手学hibernate4.1.4遇到问题
最近学习hibernate,第一个例子就出问题了,解决了几个,有出现一个新的,这个没找到方法解决,所以来求助各位前辈!
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">mysql</property>
<!-- JDBC connection pool (use the built-in) -->
<!--<property name="connection.pool_size">1</property>-->
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<!--<property name="current_session_context_class">thread</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>
<!-- Drop and re-create the database schema on startup -->
<!--<property name="hbm2ddl.auto">update</property>-->
<!--<mapping resource="com/dxd/hibernate/model/Student.hbm.xml"/>-->
<mapping class="com.dxd.hibernate.model.Student"/>
</session-factory>
</hibernate-configuration>
Student.java如下:package com.dxd.hibernate.model;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Student {
private int id;
private String name;
private int age;
@Id
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
测试类StudentTest.java如下:import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistryBuilder;
import com.dxd.hibernate.model.Student;
public class StudentTest {
public static void main(String[] args) {
Student student=new Student();
student.setId(1);
student.setName("nihao");
student.setAge(20);
Configuration cfg=new Configuration();
SessionFactory sf=cfg.configure().buildSessionFactory(ne