美文网首页
hibernate详解(十三)继承关系映射

hibernate详解(十三)继承关系映射

作者: 秀逼 | 来源:发表于2017-11-06 23:51 被阅读0次

每个具体子类映射一张表:

sql语句:

/* 每个具体子类映射一张表 */
CREATE TABLE t_concrete_bankaccount(
    id NUMBER(10) PRIMARY KEY,
    owner VARCHAR2(15),
    code VARCHAR2(15),
    created DATE,
    bankname VARCHAR2(20),
    bankswift VARCHAR2(20)
);

CREATE TABLE t_concrete_creditcart(
    id NUMBER(10) PRIMARY KEY,
    owner VARCHAR2(15),
    code VARCHAR2(15),
    created DATE,
    credit_card_type VARCHAR2(20),
    expired_month VARCHAR2(20),
    expired_year VARCHAR2(20)
);

映射文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.iotek.basic.inheritance.pojo">
    <class name="BillingDetails">
        <id name="id" column="ID" type="long">
            <generator class="sequence">
                <param name="sequence">t_billing_seq</param>
            </generator>
        </id>
        
        <property name="owner" type="string" column="OWNER"/>
        <property name="created" type="date" column="CREATED"/>
        <property name="code" type="string" column="CODE"/>
        
        <union-subclass name="CreditCard" table="T_CONCRETE_CREDITCART">
            <property name="type" type="string" column="CREDIT_CARD_TYPE" />
            <property name="expMonth" type="string" column="EXPIRED_MONTH" />
            <property name="expYear" type="string" column="EXPIRED_YEAR" />
        </union-subclass>
        
        <union-subclass name="BankAccount" table="T_CONCRETE_BANKACCOUNT">
            <property name="bankName" type="string" column="BANKNAME" />
            <property name="bankSwift" type="string" column="BANKSWIFT" />
        </union-subclass>
    </class>
</hibernate-mapping>
1.png 2.png

相关文章

网友评论

      本文标题:hibernate详解(十三)继承关系映射

      本文链接:https://www.haomeiwen.com/subject/xcgrmxtx.html