zoukankan      html  css  js  c++  java
  • Hibernate: Implicit & Explicit Polymorphism

    As I was going through the various inheritance strategies in Hibernate, I came across the ‘class’ element’s attribute, polymorphism=”implicit|explicit”.

    From the Hibernate’s reference manual, this is what I found as definitions for implicit and explicit polymorphism.

    Implicit Polymorphism:

    Implicit polymorphism means that instances of the class will be returned by a query that names any superclass or implemented interface or the class and that instances of any subclass of the class will be returned by a query that names the class itself. For most purposes the default, polymorphism=”implicit”, is appropriate.

    In simple terms, for getting a better idea about Implicit polymorphism, here is a scenario. Consider a program that manipulates lists of several different types of elements. One approach is to define a separate composite class hierarchy for each kind of list. But this approach requires replicating essentially the same code in the definition of each class. To avoid this code replication, we can define a single composite class hierarchy for lists of type Object. Since all Java object types are subtypes of Object, such a list type can be used in place of any specific list type. However, when we extract an element from such a list, we will generally have to cast it to the specific type required by the context in which it is used.

    Explicit Polymorphism:

    Explicit polymorphism means that class instances will be returned only by queries that explicitly name that class and that queries that name the class will return only instances of subclasses mapped inside this <class> declaration as a <subclass> or <joined-subclass>.

    Explicit polymorphism is useful when two different classes are mapped to the same table (this allows a “lightweight” class that contains a subset of the table columns).

    Further beyond all the findings and explanations, I was still in need of a clear living example for understand the concept, especially about explicit polymorphism and its usage. Eventually I landed up in a much better place than expected which gave me a right picture of how polymorphism strategies work in Hibernate.

    Light weight Class: http://www.hibernate.org/41.html

    I hope the article in the above link have given you a better understanding too.

  • 相关阅读:
    在给定的区间上对每个数都开方 最后还是在一段上求和
    简单的覆盖问题,,通过覆盖的g不同 有这不同的价值 最后还是一段上求和
    codevs 3094 寻找sb4
    noi 04:网线主管
    codevs 1031 质数环
    codevs 1061 重复子串
    codevs 1204 寻找子串位置
    codevs 3223 素数密度
    各种用法
    codevs1073 家族
  • 原文地址:https://www.cnblogs.com/zjoch/p/4676911.html
Copyright © 2011-2022 走看看