Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ORM and Object Mapping?

On Spring Boot tutorial site I read the following:

Great thing about Spring Framework is that it does not try to solve problems which are already solved. All that it does is to provide a great integration with frameworks which provide great solutions.

  • Hibernate for ORM
  • iBatis for Object Mapping

That's how Hibernate explains its purpose:

Hibernate ORM enables developers to more easily write applications whose data outlives the application process. As an Object/Relational Mapping (ORM) framework, Hibernate is concerned with data persistence as it applies to relational databases (via JDBC).

Apart from the fact that iBatis changed the name to MyBatis, the solution MyBatis offers seems to be different from ORM approach. On their introduction page, MyBatis's creators write:

MyBatis is a first class persistence framework with support for custom SQL, stored procedures and advanced mappings. MyBatis eliminates almost all of the JDBC code and manual setting of parameters and retrieval of results. MyBatis can use simple XML or Annotations for configuration and map primitives, Map interfaces and Java POJOs (Plain Old Java Objects) to database records.

So my guess is that Object Mapping must be closer to the database, SQL, stored procedures and the like. I don't know if it can be applied to NoSQL databases. Whereas, ORM concerns only relational databases.

Is ORM really different from Object Mapping or are they synonyms? What is the difference?

like image 539
banan3'14 Avatar asked Sep 22 '18 18:09

banan3'14


Video Answer


2 Answers

So my guess is that Object Mapping must be closer to the database, SQL, stored procedures and the like. I don't know if it can be applied to NoSQL databases. Whereas, ORM concerns only relational databases.

Yes, when it comes to difference between mybatis and hibernate. Here is a good explanation which clarifies this difference quite well in your case.

Is ORM really different from Object Mapping or are they synonyms? What is the difference?

About the term "object mapping": it can also mean some other things that necessarily not have any relation to databases or so. For example Jackson might use object mapper to map Json data to some java POJO.

I tend to speak (and hear) about ORM when it goes with @Entity & JPA implementations so quite high level / abstraction stuff.

Object mapping on the other hand - at least in Java- can mean anything that maps arbitrary data to object, object to another object or object to arbitrary data (like a row in a db table).

But not that I do not mean that term object mapping should be used that way, however this might also be interesting reading.

like image 50
pirho Avatar answered Oct 18 '22 19:10

pirho


The main difference between Hibernate (or more broadly any JPA implementation) and MyBatis is the focus.

JPA focuses on entities in the sense that the main thing you define is entity with all its fields and relations to other entities. Then you can do queries using some high level API and framework generates SQL queries for you. Note that queries you use are defined in terms of entities and their fields as opposed to tables and table columns.

In mybatis the main thing is SQL query. You define the query and the way to map query results to objects. The query you create is plain SQL that is it is defined in terms of database tables and table columns. You fully control this process, there is no high level API that generates the query for you (the available java API is not the same as JPA query API, as it works with query more like with a string template and works directly with SQL, where JPA focuses on objects and their relationships).

JPA allows to use native query so JPA can be used in a mybatis-like style in addition to working purely with entities whereas mybatis does not allow to query in terms of entities.

Regarding the naming ORM vs Object Mapping it is really the matter of definitions. If you look to the definition and description of ORM in wikipedia you can see that mybatis is an ORM. Object Mapping is not a wide spread term and it is hard to say what the author of the tutorial really meant.

like image 1
Roman Konoval Avatar answered Oct 18 '22 18:10

Roman Konoval