1. 到官网:http://hibernate.org/orm/ 下载最新的Hibernate
2. 在eclipse中安装Hibernate tool插件
最新的luna插件下载地址在:http://download.jboss.org/jbosstools/updates/stable/luna/
安装好有,在新建菜单里应该有:
3. 新建一个新的java工程
将下载好的hibernate中的/lib/required包里的所有jar包都添加进去,连接数据库的驱动也要添加进去.
4. 在src目录下新建一个hibernate.cfg.xml的配置文件(用插件新建就可以了)
xml里写上数据库信息和一些设置
<?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.username">javaTest</property>
<property name="connection.password">123456</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/sample</property>
<!-- 配置hibernate 基本信息 -->
<!-- 方言 -->
<property name="dialetc">org.hibernate.dialect.MySQLInnoDBDialect</property>
<!-- 打印sql -->
<property name="show_sql">true