
<?xml version=‘1.0‘ encoding=‘utf-8‘?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="connection.username">test</property>
<property name="connection.password">test</property>
<property name="connection.pool_size">2</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<mapping resource="cn/javass/h4/hello/UserModel.hbm.xml"/>
</session-factory>
</hibernate-configuration> <?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‘>
<hibernate-mapping>
<class name="cn.javass.h4.hello.UserModel" table="tbl_user">
<id name="uuid">
<generator class="assigned"/>
</id>
<property name=“userId”></property>
<property name=“name”></property>
<property name="age"></property>
</class>
</hibernate-mapping> package cn.javass.h4.hello;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class Client {
public static void main(String[] args) {
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session s = null;
Transaction t = null;
try{
//准备数据
UserModel um = new UserModel();
um.setUuid("1");
um.setUserId("id1");
um.setName("name1");
um.setAge(1);
s = sf.openSession();
t = s.beginTransaction();
s.save(um);
t.commit();
}catch(Exception err){
t.rollback();
err.printStackTrace();
}finally{
s.close();
}
}
} 原文:http://blog.csdn.net/xiangzhihong8/article/details/52496709