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.

最新文章

  1. Java—字符串小结
  2. Could not load type &#39;System.Runtime.CompilerServices.ExtensionAttribute&#39;
  3. PHP 运行方式(PHP SAPI介绍)
  4. hdu 5188 dfs+二分
  5. As.net WebAPI CORS, 开启跨源访问,解决错误No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource
  6. URAL 1152. False Mirrors (记忆化搜索 状压DP)
  7. Cocos2d-x使用iOS游戏内付费IAP(C++篇)
  8. flask开发restful api系列(8)-再谈项目结构
  9. kafka文档翻译(一)
  10. JSONPath使用
  11. 标注-隐马尔可夫模型HMM的探究
  12. Hibernate的条件查询的几种方式
  13. 解决echarts饼图不显示数据为0的数据
  14. wordpress-基础插件,常用函数
  15. centos7下安装samba服务器
  16. Springboot 事务处理常见坑点
  17. @+id/和android:id有什么区别?
  18. Mock.js 虚拟接口 数据模拟
  19. 手动封装on,emit,off
  20. Samsung_tiny4412(驱动笔记03)----字符设备驱动基本操作及调用流程

热门文章

  1. Code Conventions for the JavaScript Programming Language
  2. centos 6.x 部署uwsgi+flask项目
  3. c++实现二叉树的非递归创建以及非递归先序、中序、后序遍历
  4. CCF CSP 201609-4 交通规划
  5. poj1979 Red And Black(DFS)
  6. js缓存加密
  7. webview内部跳转判断
  8. .NET常用的异常类型及其中文说明
  9. 【小思考】Python的float转换精度损失所想到的
  10. Win10 重装后,必须修改的设置