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

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

作者: 秀逼 | 来源:发表于2017-11-06 23:20 被阅读0次
    每个类映射一张表

    SQL语句:

    /* 每个类映射一张表 */
    CREATE TABLE t_join_billingdetails(
        id NUMBER(10) PRIMARY KEY,
        owner VARCHAR2(15),
        code VARCHAR2(15),
        created DATE
    );
    
    CREATE TABLE t_join_bankaccount(
        billing_id NUMBER(10) PRIMARY KEY,
        bankname VARCHAR2(20),
        bankswift VARCHAR2(20),
        FOREIGN KEY(billing_id) REFERENCES t_join_billingdetails(id)
    );
    
    CREATE TABLE t_join_creditcart(
        billing_id NUMBER(10) PRIMARY KEY,
        credit_cart_type VARCHAR2(20),
        expired_month VARCHAR2(20),
        expired_year VARCHAR2(20),
        FOREIGN KEY(billing_id) REFERENCES t_join_billingdetails(id)
    );
    

    映射文件:

    <?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" table="T_JOIN_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"/>
            
            <joined-subclass name="CreditCard" table="T_JOIN_CREDITCART">
                <key column="BILLING_ID" />
                <property name="type" type="string" column="CREDIT_CART_TYPE" />
                <property name="expMonth" type="string" column="EXPIRED_MONTH" />
                <property name="expYear" type="string" column="EXPIRED_YEAR" />
            </joined-subclass>
            
            <joined-subclass name="BankAccount" table="T_JOIN_BANKACCOUNT">
                <key column="BILLING_ID" />
                <property name="bankName" type="string" column="BANKNAME" />
                <property name="bankSwift" type="string" column="BANKSWIFT" />
            </joined-subclass>
        </class>
    </hibernate-mapping>
    

    类的结构与上一讲的相同,在这里就不列举出来了。

    相关文章

      网友评论

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

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