Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Object/Relational mismatch

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.

like image 351
Naved Ali Avatar asked Nov 03 '25 21:11

Naved Ali


1 Answers

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.

like image 127
Jesper Avatar answered Nov 06 '25 16:11

Jesper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!