Hibernate Auto-generate .hbm and .java

This is one of the best descriptions of how to use the Hibernate tools to reverse engineer a DB into ,hbm and .java files automatically.

I will post the description here if it will ever disappear.

  1. Download the hibernate-tools jar. [i]
  2. Extract the jar to plugins folder of Eclipse.
  3. Start eclipse.
  4. Click on [File -> New -> Other -> Hibernate -> Hibernate Configuration File] and create a cfg file. The following properties should be specified : jdbc url , username, password, DB schema, driver class and dialect.
  5. Click on [File -> New -> Other -> Hibernate -> Hibernate Console Configuration ] and create a new console configuration. Add the jar file that contains your DB driver in the classpath section at the bottom.
  6. Enter the name of the console configuration. Click Browse button against the Configuration file and select the cfg.xml file created in step 4.
  7. Click on [File -> New -> Other -> Hibernate -> Hibernate Reverse Engineering File(reveng.xml) ] and select the location of the file.
  8. Select the cfg.xml file created in step 4 as the Console Configuration. Click on include button and specift the schema and table name(s) to reverse engineer. Multiple table names can be specifed using sql wild char (eg: TBL_%). Click Finish.
  9. Click on the Hibernate icon in the tool bar and select the [Hibernate Code Generation ..] option.
  10. Right click on the [Hibernate Code Generation]tree node and select New.
  11. Give the name of the configuration and select the console configuartion created in setp 5 and reveng.xml created in step6-7. Also select the Output Directory,
  12. Go to the Exporters tab and check Generate domain code(.java) and Generate mappings (hbm.xml). Click run.
  13. The hibernate mapping xml files and Java classes will be created in the output directory specified in step 11.

UPDATE: [i] Some of the new versions of eclipse come with the tools pre installed, if your version has the tools preinstalled jump to step 4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值