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 ...
随机推荐
- group by 并且 count(1)的linq写法
SELECT [MobleNo],count(1) FROM [CustMobleNo] group by [MobleNo] GO ===作用等于=== var rst = from c in da ...
- centos7.2下caffe的安装及编译
1.前期准备 安装依赖 sudo yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5 ...
- MySql数据库 主从复制/共享 报错
从 获取不到 共享主的数据, 错误信息: Waiting for master to send event 解决方案: // 1. 从V表获取PrNo的数据 select * from Vendor_ ...
- CentOS7的firewall和安装iptables
前言:CentOS7 的防火墙默认使用是firewall,而我们通常使用iptables: 本文记录了firewall基础的命令和iptables的安装和使用. firewall部分: part1 : ...
- hdu 5120(求两个圆环相交的面积 2014北京现场赛 I题)
两个圆环的内外径相同 给出内外径 和 两个圆心 求两个圆环相交的面积 画下图可以知道 就是两个大圆交-2*小圆与大圆交+2小圆交 Sample Input22 30 00 02 30 05 0 Sam ...
- information that should help you find out what is causing the crash.
091130 11:16:11 - mysqld got exception 0xc0000005 ; This could be because you hit a bug. It is also ...
- 【LOJ】#2430. 「POI2014」沙拉餐厅 Salad Bar
题解 波兰人的j是苹果,p是橘子 还真是跟中国过不去啊= =写的时候很难受 我们先求出每个点作为起点,能延伸到的最大长度,这个可以处理成前缀和,查询一下区间最小值是不是小于0,用st表实现,如果区间最 ...
- 如何解决谷歌Chrome浏览器空白页的问题
如何解决谷歌Chrome浏览器空白页的问题 谷歌Chrome浏览器突然不打开任何网页,无论是任何站点(如http://www.baidu.com), 还是Chrome浏览器的设置页面(chrome ...
- 二、 sql*plus常用命令
一.sys用户和system用户Oracle安装会自动的生成sys用户和system用户(1).sys用户是超级用户,具有最高权限,具有sysdba角色,有create database的权限,该用户 ...
- HBase集群的搭建
HBase集群的搭建(在<HBase伪分布式安装>基础上搭建) 1 集群结构,主节点(hmaster)是hadoop0,从节点(region server)是hadoop1和hadoop2 ...