Eclipse快速上手Hibernate--4. 继承映射(2)
2008-02-23 09:52:10来源:互联网 阅读 ()
Vehicle.java
/* * Hibernate - 继承映射(每个子类一个表) * 创建日期 2005-4-9 * @author javamxj(分享java快乐) * @link Blog: htpp://javamxj.mblogger.cn * htpp://blog.csdn.net/javamxj/ */package javamxj.inheritance.two;/** * @hibernate.class */public class Vehicle { private Long id; private String name; /** * @hibernate.id * column="ID" * generator-class="hilo" * unsaved-value="null" */ public Long getId() { return id; } public void setId(Long id) { this.id = id; } /** * @hibernate.property * length = "24" */ public String getName() { return name; } public void setName(String name) { this.name = name; }}
· 子类Car.javaCar.java
package javamxj.inheritance.two;/** * @hibernate.joined-subclass * @hibernate.joined-subclass-key * column="id" */public class Car extends Vehicle { private String seat; /** * @hibernate.property * column = "载客" * length = "24" */ public String getSeat() { return seat; } public void setSeat(String seat) { this.seat = seat; }}
· 子类Truck.javaTruck.java
package javamxj.inheritance.two;/** * @hibernate.joined-subclass * @hibernate.joined-subclass-key * column="id" */public class Truck extends Vehicle { private String load; /** * @hibernate.property * column = "载重" * length = "24" */ public String getLoad() { return load; } public void setLoad(String load) { this.load = load; }}
· 这两个子类都很简单,注意添加的hibernate.joined-subclass的标记。 · 好了,这时整个项目的结构如下: 3. 运行任务 · 双击“generate-hbm”任务,会发现在包中多了一个Vehicle.hbm.XML文件。如果没有,按F5键刷新一下(这里建议打开Eclipse的“首选项”对话框,在“工作台”中勾选“自动刷新工作空间”和“在构建之前自动保存”这两项,这样以后不用每次都刷新了)。
Vehicle.hbm.xml
<?xml version="1.0" encoding="GBK"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"><hibernate-mapping> <class name="javamxj.inheritance.two.Vehicle" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version" > <id name="id" column="ID" type="java.lang.Long" unsaved-value="null" > <generator class="hilo"> <!-- To add non XDoclet generator parameters, create a file named hibernate-generator-params-Vehicle.xml containing the additional parameters and place it in your merge dir. --> </generator> </id> <property name="name" type="java.lang.String" update="true" insert="true" Access="property" column="name" length="24" /> <!-- To add non XDoclet property mappings, create a file named hibernate-properties-Vehicle.xml containing the additional properties and place it in your merge dir. --> <joined-subclass name="javamxj.inheritance.two.Truck" dynamic-update="false" dynamic-insert="false" > <key column="id" /> <property name="load" type="java.lang.String" update="true" insert="true" access="property" column="载重" length="24" /> </joined-subclass> <joined-subclass name="javamxj.inheritance.two.Car" dynamic-update="false" dynamic-insert="false" > <key column="id" /> <property name="seat" type="java.lang.String" update="true" insert="true" access="property" column="载客" length="24" /> </joined-subclass> </class></hibernate-mapping>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:JAXP跟DOM4J是什么关系?
- Eclipse快速上手Hibernate--4. 继承映射(3) 2008-02-23
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash