eclipse中hibernate反创建java和hbm.xml文件

1、安装插件

2、创建hibernate.cfg.xml文件

3、创建hibernate.reveng.xml文件

4 、run

<span style="font-size:18px;"><a target=_blank href="http://blog.sina.com.cn/s/blog_451f596201016m5q.html">http://blog.sina.com.cn/s/blog_451f596201016m5q.html</a></span>
<p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">很多时候我们已经设计好了数据库,需要使用hibernate来做数据持久化,因此需要根据数据库中的表结构生成相应的POJO.</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">本例使用hibernatetools来自动创建pojo。</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">测试环境:eclipse3.7(indigo)+hibernate4.1+hibernatetools3.3+oracle10g</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><span style="word-wrap: normal; word-break: normal; line-height: 24px;font-size:14px;"><strong>1.下载hibernatetools插件</strong></span></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">hibernatetools可从官网下载,但是需要注意下载和自己使用的eclipse版本对应的版本包,然后安装到eclipse中取,link安装方式参见:<a target=_blank href="http://maimode.iteye.com/blog/1164524" style="text-decoration: none; color: rgb(62, 115, 160);">http://maimode.iteye.com/blog/1164524</a></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">下载地址:</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">1、首先,要去Hibernate的网站下载这个工具包。一个大约14M的ZIP压缩文件。
<a target=_blank href="http://jaist.dl.sourceforge.net/sourceforge/jboss/HibernateTools-3.2.4.Beta1-R200810311334.zip" target="_blank" style="text-decoration: none; color: rgb(62, 115, 160);">http://jaist.dl.sourceforge.net/sourceforge/jboss/HibernateTools-3.2.4.Beta1-R200810311334.zip</a>
2、解压缩下载好的文件,释放出features和plugins这两个文件夹和其中的内容。完成后将这两个文件夹复制到Eclipse的目录下(这两个文件夹在Eclipse中是默认存在的,直接复制就行了)。
3、到这步为止HibernateTools的安装就算结束了</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">
</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">
</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><span style="word-wrap: normal; word-break: normal; line-height: 24px;font-size:14px;"><strong>2.创建hibernate配置文件及console配置文件</strong></span></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">新建java项目,建立包test,test.hibernate,test.model。</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">选中项目,右键-》new-》other-》hibernate-》hibernate configuration file:</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><img alt="" src="http://dl.iteye.com/upload/attachment/0072/2402/86648b10-14bd-39bc-93f1-f18fe02a8884.png" real_src="http://dl.iteye.com/upload/attachment/0072/2402/86648b10-14bd-39bc-93f1-f18fe02a8884.png" height="692" width="529" title="eclipse使用hibernate <wbr>tools插件生成POJO" action-data="http%3A%2F%2Fdl.iteye.com%2Fupload%2Fattachment%2F0072%2F2402%2F86648b10-14bd-39bc-93f1-f18fe02a8884.png" action-type="show-slide" style="margin: 0px; padding: 0px; border: 0px; list-style: none;" /></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">然后 next,配置console文件:</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><img alt="" src="http://dl.iteye.com/upload/attachment/0072/2406/eb513bb7-e4d9-3471-aacb-7cf7d5a5c4eb.png" real_src="http://dl.iteye.com/upload/attachment/0072/2406/eb513bb7-e4d9-3471-aacb-7cf7d5a5c4eb.png" title="eclipse使用hibernate <wbr>tools插件生成POJO" action-data="http%3A%2F%2Fdl.iteye.com%2Fupload%2Fattachment%2F0072%2F2406%2Feb513bb7-e4d9-3471-aacb-7cf7d5a5c4eb.png" action-type="show-slide" style="margin: 0px; padding: 0px; border: 0px; list-style: none;" /></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><span style="word-wrap: normal; word-break: normal; line-height: 24px;font-size:14px;"><strong>3.创建reverse文件</strong></span></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">选中项目,右键-》new-》other-》hibernate-》hibernate reverse engineering file</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><img alt="" src="http://dl.iteye.com/upload/attachment/0072/2412/353f0496-995d-3d3b-a28f-27326381ca58.png" real_src="http://dl.iteye.com/upload/attachment/0072/2412/353f0496-995d-3d3b-a28f-27326381ca58.png" height="621" width="635" title="eclipse使用hibernate <wbr>tools插件生成POJO" action-data="http%3A%2F%2Fdl.iteye.com%2Fupload%2Fattachment%2F0072%2F2412%2F353f0496-995d-3d3b-a28f-27326381ca58.png" action-type="show-slide" style="margin: 0px; padding: 0px; border: 0px; list-style: none;" /></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">下一步,配置要生成POJO对应的表:</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><img alt="" src="http://dl.iteye.com/upload/attachment/0072/2783/31d94b53-caec-358d-8e9b-f1837b9d1a54.png" real_src="http://dl.iteye.com/upload/attachment/0072/2783/31d94b53-caec-358d-8e9b-f1837b9d1a54.png" height="621" width="635" title="eclipse使用hibernate <wbr>tools插件生成POJO" action-data="http%3A%2F%2Fdl.iteye.com%2Fupload%2Fattachment%2F0072%2F2783%2F31d94b53-caec-358d-8e9b-f1837b9d1a54.png" action-type="show-slide" style="margin: 0px; padding: 0px; border: 0px; list-style: none;" /></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><span style="word-wrap: normal; word-break: normal; line-height: 24px;font-size:14px;"><strong>4.反向工程创建pojo</strong></span></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">在hibernate code generation configuration菜单中配置</p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><img alt="" src="http://dl.iteye.com/upload/attachment/0072/2418/a98128bd-4ec9-3a7d-adfa-f5dfc08b7225.png" real_src="http://dl.iteye.com/upload/attachment/0072/2418/a98128bd-4ec9-3a7d-adfa-f5dfc08b7225.png" height="117" width="410" title="eclipse使用hibernate <wbr>tools插件生成POJO" action-data="http%3A%2F%2Fdl.iteye.com%2Fupload%2Fattachment%2F0072%2F2418%2Fa98128bd-4ec9-3a7d-adfa-f5dfc08b7225.png" action-type="show-slide" style="margin: 0px; padding: 0px; border: 0px; list-style: none;" /></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><img title="点击查看原始大小图片" alt="" src="http://dl.iteye.com/upload/attachment/0072/2410/6467b8aa-d9d4-3136-aad8-de1d374f8ec5.png" real_src="http://dl.iteye.com/upload/attachment/0072/2410/6467b8aa-d9d4-3136-aad8-de1d374f8ec5.png" height="498" width="700" action-data="http%3A%2F%2Fdl.iteye.com%2Fupload%2Fattachment%2F0072%2F2410%2F6467b8aa-d9d4-3136-aad8-de1d374f8ec5.png" action-type="show-slide" style="margin: 0px; padding: 0px; border: 0px; list-style: none; max-width: 100%;" /></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><img title="点击查看原始大小图片" alt="" src="http://dl.iteye.com/upload/attachment/0072/2408/d4e1be82-167e-3570-b9ab-9465d2b6de5b.png" real_src="http://dl.iteye.com/upload/attachment/0072/2408/d4e1be82-167e-3570-b9ab-9465d2b6de5b.png" height="498" width="700" action-data="http%3A%2F%2Fdl.iteye.com%2Fupload%2Fattachment%2F0072%2F2408%2Fd4e1be82-167e-3570-b9ab-9465d2b6de5b.png" action-type="show-slide" style="margin: 0px; padding: 0px; border: 0px; list-style: none; max-width: 100%;" /></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><em><span style="word-wrap: normal; word-break: normal; line-height: 19.5px;font-size:12px;">执行run后便生成了相应的pojo文件:</span></em></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"><img alt="" src="http://dl.iteye.com/upload/attachment/0072/2422/3f98db03-072d-3cb5-bd7e-b12e5ac08229.png" real_src="http://dl.iteye.com/upload/attachment/0072/2422/3f98db03-072d-3cb5-bd7e-b12e5ac08229.png" height="344" width="254" title="eclipse使用hibernate <wbr>tools插件生成POJO" action-data="http%3A%2F%2Fdl.iteye.com%2Fupload%2Fattachment%2F0072%2F2422%2F3f98db03-072d-3cb5-bd7e-b12e5ac08229.png" action-type="show-slide" style="margin: 0px; padding: 0px; border: 0px; list-style: none;" /></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; background-color: rgb(188, 211, 229);">一般自动生成的mapping文件(XXX.hbm.xml)都需要修改后才能使用。</p><div>
</div>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值