ORM 和对象映射之间的区别?

Difference between ORM and Object Mapping?

在 Spring 引导教程网站上,我阅读了以下内容:

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

Hibernate 是这样解释它的目的的:

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).

除了iBatis 改名为MyBatis 之外,MyBatis 提供的解决方案似乎与ORM 方法不同。在他们的 introduction page 上,MyBatis 的创建者写道:

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.

所以我的猜测是Object Mapping一定更接近于数据库,SQL,存储过程之类的。不知道能不能用在NoSQL的数据库上。然而,ORM 仅涉及关系数据库。

ORMObject Mapping 真的不同吗?还是它们是同义词?有什么区别?

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.

是的,说到mybatis和hibernate的区别。 Here 是一个很好的解释,在您的案例中很好地阐明了这种差异。

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

关于术语"object mapping":它还可以指一些其他不一定与数据库有任何关系的东西。例如,Jackson 可能会使用对象映射器将 Json 数据映射到某些 java POJO。

当 ORM 与 @EntityJPA 实现如此高级/抽象的东西一起使用时,我倾向于谈论(和听到)它。

另一方面,对象映射 - 至少在 Java - 可以表示将任意数据映射到对象、对象映射到另一个对象或对象映射到任意数据的任何事物(比如数据库中的一行 table).

但我并不是说 对象映射 应该这样使用,但是 this 也可能很有趣。

Hibernate(或更广泛的任何 JPA 实现)和 MyBatis 之间的主要区别在于焦点。

JPA 关注实体,因为您定义的主要内容是具有所有字段和与其他实体的关系的实体。然后您可以使用一些高级 API 进行查询,框架会为您生成 SQL 查询。请注意,您使用的查询是根据实体及其字段定义的,而不是 table 和 table 列。

在mybatis中最主要的就是SQL查询。您定义查询以及将查询结果映射到对象的方式。您创建的查询是普通的 SQL,它是根据数据库 table 和 table 列定义的。您完全控制这个过程,没有高级 API 为您生成查询(可用的 java API 与 JPA 查询 API 不同,因为它使用查询更像是使用字符串模板,并直接使用 SQL,其中 JPA 专注于对象及其关系)。

JPA 允许使用本机查询,因此除了纯粹与实体一起工作之外,JPA 还可以用于类似于 mybatis 的样式,而 mybatis 不允许根据实体进行查询。

关于命名 ORMObject Mapping 这实际上是定义的问题。如果你查看wikipedia中对ORM的定义和描述,你会发现mybatis是一个ORM。 Object Mapping 不是一个广泛传播的术语,很难说出教程作者的真正意思。