使用hibernate tools插件生成POJO

很多时候我们已经设计好了数据库,需要使用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)都需要修改后才能使用。

猜你喜欢

转载自maimode.iteye.com/blog/1630670
今日推荐