ORM

ORM

What is Object/Relational Mapping

http://hibernate.org/orm/what-is-an-orm/
Object Relational Mapping
对象关系映射

Object-relational mapping(ORM, O/RM, and O/R mapping tool) in computer science is a programming technique for converting data between incompatible type systems using object-oriented programming languages. This creates, in effect, a "virtual object database" that can

Many popular database products such as SQL database management systems(DBMS) can only store and manipulate scalar values such as integers and strings organized within tables. The programmer must either convert the object values into groups of simpler values for storage in the database(and convert them back upon retrieval), or only use simple scalar values within the program. Object-relational mapping implements the first approach.

The heart of the problem involves translating the logical representation of the objects into an atomized form that is capable of being stored in the database while preserving the properties of the objects and their relationships so that they can be reloaded as objects when needed. If this storage and retrieval functionality is implemented, the objects are said to be persistent.

与传统数据存取技术的对比

优点:
ORM 要写的代码更少

缺点:
ORM tools 的使用,使得我们不能在代码中使用复杂的实现代码。

Persistence

Persistence simply means that we would like our application's data to outlive the applications process. In Java terms, we would like the state of (some of) out objects to live beyond the scope of the JVM so that same state is available later.

  • (在 Hibernate 中)ORM,是为了帮助应用程序获得持久性,也就是希望应用程序的数据能生存得比应用进程更久一点。

Relational Databases

Specifically, Hibernate ORM is concerned with data persistence as it applies to relational databases(RDBMS). In the world of Object-Oriented applications, there is often a discussion about using an object database(ODBMS) as opposed to a RDBMS. We are not going to explore that discussion here. Suffice it to say that RDBMS remain a very popular persistence mechanism and will so for the foreseeable future.

  • 具体来说,(Hibernate) ORM 是关心关系型数据库中的数据持久性。

The Object-Relational Impedance Mismatch

‘Object-Relational Impedance Mismatch’(sometimes called the ‘paradigm mismatch’)is just a fancy way of saying that object models and relational models do not work very well together. RDBMSs represent data in a tabular format(a spreadsheet is a good visualization for those not familiar with RDBMSs), whereas object-oriented languages, such as Java, represent it as an interconnected graph of objects. Loading and storing graphs of objects using a tabular relational database exposes us to 5 mismatch problems...

  • Object-Relational Impedance Mismatch 是指 object models 和 relational models 不能很好的配合工作。RDBMSs 用列的形式来表示数据,面向对象语言,比如 Java。从 RDBMSs 中读取或者存储 graphs of objects 的数据时,暴露给我们 5 个 mismatch problems

粒度

继承

继承是面向对象语言中一个常见的特性,然而,RDBMSs 并不定义任何类似的东西。

身份

RDBMS 通过 the primary key 来识别唯一性,java,则是来通过 a.equals(b) 来确定 a == b。

关联

关联在面向对象语言里是通过单向的引用,而在RDBMSs 里是通过foreign keys。如果在 Java 里要用到双向的关系,就必须定义 association 两次。

数据浏览

In Java,you navigate from one association to an other walking the object network.
You typically want to minimize the number of SQL queries and thus load several entities via JOINs and select the targeted entities before you start walking the object net work.

Persistence Layer, ORM(Object-Relation Mapping), DAO(Data Access Object) 的区别

持久层(Persistence Layer)是软件体系结构的中的一层,相对于业务层和展示层等。数据访问对象(Data Access Object)是面向对象软件中对访问RDBMS或文件系统的一个封装的模式,通常是将数据访问这部分的逻辑与业务逻辑分离,保证业务对象的代码不随持久化方式的变化而变化。这个模式只是很多持久层模式中的一种。ORM(Object-Relation Mapping),是一种软件技术,解决的问题是面向对象的软件和关系型数据库的不匹配的问题,将对象,对象的属性,以及对象之间的关系保存在关系型数据库的表中。通过配置建立对象和表的映射关系,而由系统自动生成插入,更新,删除和查询的SQL语句。这类技术包括Hibernate、iBatis等。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,168评论 0 10
  • 大学三年级了,出去做过家教,促销员,播音,饭店服务员等兼职,在学校里也勤工助学;在学校里参加过舞蹈,小品...
    且如微风阅读 1,468评论 0 0
  • 曾经在3-8岁小朋友群体中红极一时的《歪歪兔和她的朋友们》第二季强势回归!据悉,这部国内首部原创手偶动画剧正在紧锣...
    孤独症康复阅读 3,222评论 0 1
  • 所有云淡风轻的喜欢 都在今天之后明天之前不了了之 和黑色一样消逝在黑夜中 其实有那些时候我在想 你说一句流浪天涯 ...
    故生阅读 2,962评论 0 3
  • 说实话 我不过是一个伪文青 我喜欢文艺的生活 可是我却很少购买装饰去营造 不是因为我没时间 其实是懒 所以 生活还...
    一杯野性的白开阅读 3,564评论 0 1

友情链接更多精彩内容