1、下好hibernate包
1)必须导入的包:hibernateXXX/lib/required
2)可选的jar包:hibernateXXX/lib/optional
3)导入mysql连接包mysql-connector-java-xxx
4)导入log4j包
2、配置hibernate xml 文件 hibernate.cfg.xml
配置文件可以在hibernateXXX/project/etc/hibernate.cfg.xml找到
配置参数可以在hibernateXXX/project/etc/hibernate.properties找到
## MySQL
##方言选一个
#hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
##驱动
#hibernate.connection.driver_class com.mysql.jdbc.Driver
##数据库连接url
#hibernate.connection.url jdbc:mysql:///test
##数据库连接 账号
#hibernate.connection.username gavin
/##数据库连接 啊密码
#hibernate.connection.password
## auto schema export
//对象和数据库表对应
#hibernate.hbm2ddl.auto create-drop
#hibernate.hbm2ddl.auto create
#hibernate.hbm2ddl.auto update
#hibernate.hbm2ddl.auto validate
3、配置hbm.xml文件,关联实体对象与数据库表
<hibernate-mapping package="包名">
<class name="类名" table="表名" >
<id name="id" >
<generator class="native">
</generator>
</id>
<property name ='字段名'/>
</class>
</hibernate-mapping>
在hibernate.cfg.xml文件中中加入hbm.xml文件<mapping resource="hbm.xml路径">
4、创建sessionfactory(单例)