项目结构
project
|_src
  |_mypack
  |  |_Test.java
  |  |_User.java
  |  |_User.hbm.xml
  |_hibernate.cfg.xml
===================================================================================
hibernate.cfg.xml代码:
<?xml version='1.0' encoding='GBK'?>
<!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
    
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="dialect">net.sf.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:myoracle</property>
<property name="connection.username">xxx</property>
<property name="connection.password">xxx</property>

<mapping resource="mypack/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
================================================================================
User.hbm.xml代码:
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"><hibernate-mapping>
<class name="mypack.User" table="usertable">
<id name="id">
<generator class="sequence">
                          <param name="sequence">user_id_seq</param>
                        </generator>
</id>
<property name="username"></property>
<property name="password"></property>
</class>
</hibernate-mapping>
============================================================================
User.java代码:
package mypack;public class User {
public User(){}

private int id;
private String username;
private String password;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}


}
===================================================================================
Test.java代码:
package mypack;import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;public class Test { /**
 * @param args
 */
public static void main(String[] args) {
// TODO 自动生成方法存根
try{
SessionFactory sf=new Configuration()
.configure()
.buildSessionFactory();
Session session=sf.openSession();
Transaction tx=session.beginTransaction();

User user=new User();
user.setUsername("熊昂");
user.setPassword("2368");
session.save(user);
tx.commit();
session.close();
}catch(HibernateException e){
e.printStackTrace();
}
}}
================================================================================
Sql脚本
CREATE TABLE usertable (
  ID number(6) NOT NULL primary key,
  username varchar2(24) NOT NULL,
  password varchar2(24) NOT NULL ,
);
序列:
create sequence user_id_seq increment by 1 start with 1 nomaxvalue;