• NHibernate Notes1_Creating Class Hierarchy mappings


    There are 3 ways to implement the hierarchy in NHibernate: Subclass in one table, Table per class &

    Table per concrete class

    1. Subclass in one table

    All entities of subclasses are stored in the same table.

    Father class

    <class name="Product">

    <id name="Id">

    <generator class="guid.comb" />

    </id>

    <discriminator column="ProductType" />

    <natural-id mutable="true">

    <property name="Name" not-null="true" />

    </natural-id>

    <property name="Description" />

    <property name="UnitPrice" not-null="true" />

    </class>

    Sub class

    <subclass name="Movie" extends="Product">

    <property name="Director" />

    </subclass>

     

    Notes:

    With table-per-class-hierarchy, we cannot define any of our subclass properties as

    not-null="true", because this would create a not-null constraint on those fields

     

    1. Table per class

    In table-per-class mappings, properties of the base class (Product) are stored

    in a shared table, while each subclass gets its own table for the subclass properties

    NHibernate will use a join to query forthis data

     

    subclass

    <joined-subclass name="Movie" extends="Product">

    <key column="Id" />

    <property name="Director" />

    </joined-subclass>

     

    1. Table per concrete class

    In table-per-concrete-class mappings, each class gets its own table containing columns

    for all properties of the class and the base class

    To fetch Product data, NHibernate will use unions to query athree tables.

     

    <union-subclass name="Movie" extends="Product">

    <property name="Director" />

    </union-subclass>

  • 相关阅读:
    如何理解Linux中的load averages?
    如何准备Java初级和高级的技术面试
    大数据java基础吗?
    如何写出没有BUG的代码
    求强连通分量Tarjan算法
    图论_连通_连通分量
    欧拉函数
    二分图,匈牙利算法
    网络流24题(更新中
    一些简单二分题,简单的hash,H(i),字符串题
  • 原文地址:https://www.cnblogs.com/haokaibo/p/2166824.html
Copyright © 2020-2023  润新知