当前位置: 代码迷 >> J2EE >> hibernate,该怎么处理
  详细解决方案

hibernate,该怎么处理

热度:17   发布时间:2016-04-22 01:52:03.0
hibernate

初学hibernate,在线等大家解答哦,不胜感激

student.java代码


package com.hibernate.model;

public class student {

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;
}
private int id;
private String name;
private int age;
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 com.hibernate.model.student;


public class studentTest {


public static void main(String[] args) {
student s=new student();
s.setAge(1);
s.setId(001);
s.setName("yatou");

Configuration cfg=new Configuration();
SessionFactory sf = cfg.configure().buildSessionFactory();
Session session=sf.openSession();
session.beginTransaction();
session.save(s);
session.getTransaction().commit();
session.close();
sf.close();
}

}



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">532129</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/hibernate/model/student.hbm.xml"/>

  </session-factory>

</hibernate-configuration>


student.hbm.xml代码


<hibernate-mapping package="com.hibernate.model">

  <class name="student" table="student">
  <id name="id" />
  <property name="age"/>
  <property name="name"/>  
  </class>

</hibernate-mapping>

抛出的错发代码

2012-3-25 2:55:49 org.hibernate.annotations.common.Version <clinit>
  相关解决方案