zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    servlet 与缓存(4)
    向架构师进军---&gt;系统架构设计基础知识
    sql语法:inner join on, left join on, right join on具体用法
    关于sources.list和apt-get [转载]
    SoftReference
    MFC 之 截图工具
    Outlook Express 收发邮件出现&quot;0x800CCC0F&quot;错误代码解决方法
    使用ffmpeg视频编码过程中踩的一个坑
    Libgdx环境搭建及介绍
    从简单的信道预计说起
  • 原文地址:https://www.cnblogs.com/haokaibo/p/2166824.html
Copyright © 2011-2022 走看看