第一个成功的Hibernate实例(二)[Java编程]
本文“第一个成功的Hibernate实例(二)[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
2、在Eclipse中生成POLO和映射文件
1) 在Eclipse中配置环境,包含数据库驱动程序(此处略)
2) 生成POLO类和映射文件
此处以Houses为例,生成的原代码和映射文件以下:
a) hibernate.cfg.xml
<?xml version=′1.0′ encoding=′UTF-8′?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<hibernate-configuration>
<session-factory>
<!-- properties -->
<property name="connection.username">sa</property>
<property name="connection.url">jdbc:microsoft:sqlserver://localhost:1433;databaseName=RMSDB</property>
<property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="connection.password">jckjdkmcj</property>
<property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<!-- mapping files -->
<mapping resource="zy/pro/hrms/dao/Staffs.hbm.xml"/>
<mapping resource="zy/pro/hrms/dao/Houses.hbm.xml"/>
<mapping resource="zy/pro/hrms/dao/Menus.hbm.xml"/>
<mapping resource="zy/pro/hrms/dao/Tables.hbm.xml"/>
<mapping resource="zy/pro/hrms/dao/Customers.hbm.xml"/>
<mapping resource="zy/pro/hrms/dao/Notice.hbm.xml"/>
</session-factory>
</hibernate-configuration>
b) Houses.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Fri May 13 14:09:45 CST 2005 -->
<hibernate-mapping package="zy.pro.hrms.dao">
<class name="Houses" table="Houses">
<id name="hid" column="HID" type="java.lang.Integer">
<generator class="increment"/>
</id>
<property name="alias" column="alias" type="java.lang.String" />
<property name="description" column="description" type="java.lang.String" />
<property name="capity" column="capity" type="java.lang.Integer" not-null="true" />
</class>
</hibernate-mapping>
以上是“第一个成功的Hibernate实例(二)[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |