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.
Hibernate: Implicit & Explicit Polymorphism的更多相关文章
- c# implicit explicit关键字(隐式和显式数据类型转换)
implicit关键字用于声明隐式的用户定义类型转换运算符.(explicit反之)explicit则用于显示转换用户自定义类型.static implicit operator target_typ ...
- C# - implicit, explicit
如果类型直接没有继承关系,也没有共享接口,想在这两个类型之间进行转换,就必须重载转换运算符. 此时需要关键字implicit和explicit. 下面定义了类型ConvClass1和ConvClass ...
- C#的关键字Explicit 和 Implicit
一.explicit和implicit explicit 关键字用于声明必须使用强制转换来调用的用户定义的类型转换运算符:implicit 关键字用于声明隐式的用户自定义的类型转换运算符. 总结来说: ...
- Hibernate的映射文件
映射文件的结构和属性 一个映射文件(mapping file)由一个根节点<hibernate-mapping>和多个<class>节点组成, 首先看看根节点<hiber ...
- Hibernate常用配置文件详解
本文转载自:http://blog.csdn.net/csh624366188/article/details/7578939 初学hibernate的童鞋,刚开应该都有这种感觉,hibernate的 ...
- Hibernate配置文件和映射元素解释
象关系的映射是用一个XML文档来说明的.映射文档可以使用工具来生成,如XDoclet,Middlegen和AndroMDA等.下面从一个映射的例子开始讲解映射元素. AD:干货来了,不要等!WOT20 ...
- eclipse中hibernate和mybatis中xml配置文件的没有标签提醒解决方法
当我们使用eclipse编写Mybatis或hibernate的xml文件时,面对众多标签的配置文件,却没有自动提醒,对于工作和学习都十分不方便. 之所以没有自动提醒,是因为dtd文件没有加载成功. ...
- hibernate学习(一)配置,导包
框架的作用 学过javaWeb基础的已经对web层 jsp servlet ,service 层 ,dao层的jdbc .DBUtils 有了很深的了解 并编写代码实现某种功能 为了提高开发 ...
- Hibernate 第一个体验程序
首先要导入包,将下载的hibernate所有required包导入,将下载的hibernate用来写log的slf4j的api和nopjar包导入,将下载的mysql链接引擎jar包导入. 然后新建j ...
随机推荐
- » Working Around JNI UTF-8 Strings Deprogramming
private static native void printString(String text); ... void examplePrintString() { String str = &q ...
- android拾遗——AlarmManager的使用
AlarmManager的作用文档中的解释是:在特定的时刻为我们广播一个指定的Intent.简单的说就是我们设定一个时间,然后在该时间到来时,AlarmManager为我们广播一个我们设定的Inten ...
- 如何用正确的姿势编写jQuery插件
在园子里有很多关于jQuery插件的文章,尤其 以下2篇文章: 不定义JQuery插件,不要说会JQuery jQuery插件开发精品教程,让你的jQuery提升一个台阶 这2位大神基础讲的很清楚,在 ...
- SPOJ - SUBLEX 后缀自动机
SPOJ - SUBLEX 思路:求第k大字串,求出sam上每个节点开始能识别多少字串,然后从起点开始跑就好啦. #include<bits/stdc++.h> #define LL lo ...
- Logstash 本地安装plugin
plugin的gems仓库 下载地址:仓库地址 1.安装ruby环境 yum install ruby yum install rubygems 2.下载插件包 下载插件的方式有多种 2.1 wget ...
- spring boot mybatis 多数据源配置
package com.xynet.statistics.config.dataresources; import org.springframework.jdbc.datasource.lookup ...
- POJ - 2456 Aggressive cows 二分 最大化最小值
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18099 Accepted: 8619 ...
- Spring boot之SpringApplicationBuilder,@@Configuration注解,@Component注解
SpringApplicationBuilder: 该方法的作用是可以把项目打包成war包 需要配置启动类,pom.xml文件等,具体见:http://blog.csdn.net/linzhiqian ...
- ARKit:增强现实技术在美团到餐业务的实践
前言 增强现实(Augmented Reality)是一种在视觉上呈现虚拟物体与现实场景结合的技术.Apple 公司在 2017 年 6 月正式推出了 ARKit,iOS 开发者可以在这个平台上使用简 ...
- python-arcade时钟
最近开始学习arcade的图形库,感觉功能很丰富,尝试画了个时钟,显示如下: 贴上调整好的代码: import arcade import math,time SCREEN_WIDTH = 800 S ...