利用Hibernate Tool 连接数据库, 生成java和hbm.xml

来源:互联网 发布:淘宝达人互粉平台 编辑:程序博客网 时间:2024/04/28 10:45

1,在 http://www.hibernate.org/6.html  下载 Hibernate Tools

2,解压Hibernate Tools , 把plugin目录下的文件拷贝到eclipse的对应目录下。 在目录hibernate tools/plugins/org.hibernate.eclipse_3.2.0.GA/lib/tools中,找到hibernate-tools.jar

3,生成一个Java工程,把hibernate-tools.jar加到 Build Path.

4, 右键点击src,执行 new -> Other -> Hibernate (Hibernate Configuration File(cfg.xml)) -> next -> next

5,填写Database dialect, Driver class, Connection URL, Username, Password, 选中Create a console Configuration, 选中Next -> Finished

6,执行Window -> Show View -> Other, 选择"Hibernate Configuration"

7,  点击 刚才的工程,看是否能看到所链接数据库中的表,如果有错,则检查相关的JDBC Driver是否加入Build Path中。然后在工程名上点击右键,在上下文菜单中,选择“Rebuild Configuration”。

8, 点击Eclispe工具栏中的Hibernate运行图标。Open hibernate Code Generation Dialog.

9, 修改: Console configuration, Output directory,  Reverse engineer from JDBC Connection, Package(com.bt.xxx.entity),  Exporters --> User Java5 syntqax,Generate EJB5 annotations可以不选,Hibernate XML Mapperings  --> RUN

 

原创粉丝点击