What is Object/Relational mismatch

南楼画角 提交于 2020-01-15 09:35:08

问题


I am a newbie to java and was reading about Object Relational Mapping. I found a term Object/Relational mismatch on this link Hibernate

Can anyone explain what is Object/Relational mismatch in terms of Java. I also read about it from haacked.com but could not get it properly.Explanation with example would be appreciable.


回答1:


Hibernate is an ORM (Object-Relational Mapping) tool. Its primary purpose is to translate concepts from object-oriented programming, such as classes, inheritance and fields, to concepts used in relational databases, such as tables, rows and columns.

For example, a class corresponds to a database table, an object (instance of a class) corresponds to a database row, and a field corresponds to a database column.

The term "object/relational mismatch" refers to the fact that there is not a clear way to translate all the concepts from object-oriented programming to relational database concepts and vice versa. Hibernate attempts to solve this problem.

For example, how do you translate inheritance to relational database concepts? There's no such thing as inheritance in a relational database, so some way has to be invented to represent this in the database. Hibernate has different ways to do this, for example by having one table for the class hierarchy with a discriminator column to determine to which subclass a row maps, or by having a table per subclass.

Likewise, there are concepts that exist in a relational database that cannot easily be translated to object oriented programming concepts.




回答2:


ORM solutions try to make it possible for object-oriented programmers to forget that they're using relational databases and deal only in objects.

Start with the difference between object-oriented languages and SQL. OO languages are procedural; SQL is declarative.

Objects are instances of classes that encapsulate state and behavior together into a single software component. Relational databases express relationships between entities that follow set theory.

Objects can use inheritance and composition. Tables can be JOINed together.

I didn't read the Hibernate article, but these would be three of the main differences that I can think of. See if those are written in a way that resonates with you.



来源:https://stackoverflow.com/questions/38305464/what-is-object-relational-mismatch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!