eclipse中集成hibernate tools插件不在描述。只需要去官方网站上下载相应的插件即可。按照以往eclipse的插件安装方式或者在线更新均可。插件装好后可以再file--》new--》-other中看到相应的hibernate选项。可以再run菜单中看到hibernate code generation字样。下面写个小例子阐述一下生成java pojo代码的简单操作。
1、配置好hibernate.cfg.xml文件
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="sessionFactory" >
<property name="hibernate.connection.url">jdbc:oracle:thin:@169.254.11.134:1521:xxxx</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">123</property>
<property name="hibernate.connection.password">123</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
</session-factory>
</hibernate-configuration>
2、配置对应的hbm文件Authority.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cn.com.xinli.lmss.entity">
<class name="Authority" table="LMSS_Authority" dynamic-insert="true" dynamic-update="true">
<id name="id" column="ID" type="string">
<generator class="uuid.hex"/>
</id>
<property name="purviewName" length="400" type="string" column="PurviewName"/>
<property name="purviewPage" length="400" type="string" column="PurviewPage"/>
</class>
</hibernate-mapping>
相应的配置就ok了。
然后在windows--show view --other 中调出hibernate configeration配置。编辑相应的配置(选择该项目,添加相应的hbm文件到mapping配置中)。到此刻相应的配置就完成了。只需要执行生成代码就ok。通过菜单run--hibernate code generation--open hibernate code generation dialog,点击后打开对话框mian选项卡中选择项目以及代码生成的路径,exporters选项卡配置需要生成的文件类型(java 、dao等)。应用后就只剩run啦。运行后将会在指定路径下生成相应的代码。大功告成。。。。hbm2java就ok了.