建立一个web项目,FirstHibernateProweb
建立一个数据库链接,这里使用的是Mysql数据库:window-->show View-->Data Source Explorer,而后在Database Connections右键 New,选择Mysql,而后去添加本身的数据库链接,而且添加详细的配置和加入相应的数据库驱动包sql
而后选择ok,开始测试本身的数据库链接,最后finish若是Database Source Exploer中出现了本身的数据库以及表则代表数据库链接建立完成,这里个人数据是test,表名是a,b数据库
在项目名称上面右键 new-->other而后选择Hibernate Configuration File(cfg.xml),而后next,测试
若是在这里忘了给Create a console configuration打钩,能够在为项目配置hibernate的时候选择Hibernate console configuration配置spa
配置好生成hibernate.cfg.xml文件后而后finish,src路径下就会出现了hibernate.cfg.xml文件hibernate
根据表生成类的实体xml
window-->Open Perspective-->other-->Hibernate;配置Hibernate Code Generation Configurations;新建一个Hibernate Code Configutaionio
最后执行Run,项目的com.hibernate.model中就会出现和咱们数据库中表相对应的实体和对应的xmlconsole