(1)创建一个实体类User
(2)将hibernate所需jar包构建项目中
(3)配置文件
hibernate.cfg.xml
hibernate.properties
驱动、url、用户名、密码、方言、自动创建表格、将hibernate工作过程中产生的sql语句输出
以及映射文件的位置
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql:///demo</property>
<property name="connection.username">root</property>
<property name="connection.password">123</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="com/hbsi/domain/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
(4)映射文件---
User---- User.hbm.xml
<hibernate-mapping
package="com.hbsi.domain"> -----指定Java实体类的包名
<class name="User" table="user"> -----说明实体类怎样映射成表
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="birthday"/>
</class>
</hibernate-mapping>
(5)写Java代码
Configuration cfg=new Configuration();
cfg.configure();//完成hibernate的初始化--读取配置文件
//SessionFactory对象----DriverManager
SessionFactory sf=cfg.buildSessionFactory();
//得Session对象
Session s=sf.openSession();
Transaction tx=s.beginTransaction();
User user=new User();
user.setName("Tom");
user.setBirthday(new Date());
s.save(user);
tx.commit();
s.close();
(2)将hibernate所需jar包构建项目中

(3)配置文件
hibernate.cfg.xml
hibernate.properties
驱动、url、用户名、密码、方言、自动创建表格、将hibernate工作过程中产生的sql语句输出
以及映射文件的位置
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql:///demo</property>
<property name="connection.username">root</property>
<property name="connection.password">123</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="com/hbsi/domain/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
(4)映射文件---
User---- User.hbm.xml
<hibernate-mapping
package="com.hbsi.domain"> -----指定Java实体类的包名
<class name="User" table="user"> -----说明实体类怎样映射成表
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="birthday"/>
</class>
</hibernate-mapping>
(5)写Java代码
Configuration cfg=new Configuration();
cfg.configure();//完成hibernate的初始化--读取配置文件
//SessionFactory对象----DriverManager
SessionFactory sf=cfg.buildSessionFactory();
//得Session对象
Session s=sf.openSession();
Transaction tx=s.beginTransaction();
User user=new User();
user.setName("Tom");
user.setBirthday(new Date());
s.save(user);
tx.commit();
s.close();