您的位置:首页 > 其它

使用hibernate tools插件生成POJO

2016-05-10 10:09 148 查看
很多时候我们已经设计好了数据库,需要使用hibernate来做数据持久化,因此需要根据数据库中的表结构生成相应的POJO.

本例使用hibernatetools来自动创建pojo。

测试环境:eclipse3.7(indigo)+hibernate4.1+hibernatetools3.3+oracle10g

1.下载hibernatetools插件

hibernatetools可从官网下载,但是需要注意下载和自己使用的eclipse版本对应的版本包,然后安装到eclipse中取,link安装方式参见:http://maimode.iteye.com/blog/1164524

2.创建hibernate配置文件及console配置文件

新建java项目,建立包test,test.hibernate,test.model。

选中项目,右键-》new-》other-》hibernate-》hibernate configuration file:



然后 next,配置console文件:



3.创建reverse文件

选中项目,右键-》new-》other-》hibernate-》hibernate reverse engineering file



下一步,配置要生成POJO对应的表:



4.反向工程创建pojo

在hibernate code generation configuration菜单中配置







执行run后便生成了相应的pojo文件:



一般自动生成的mapping文件(XXX.hbm.xml)都需要修改后才能使用。
http://maimode.iteye.com/blog/1630670
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: