Spring Data MongoDB 和 Hibernate OGM for MongoDB 有什么区别? [英] What's the difference between Spring Data MongoDB and Hibernate OGM for MongoDB?

查看:19
本文介绍了Spring Data MongoDB 和 Hibernate OGM for MongoDB 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前没有使用过 Spring Data,但我已经多次使用 Hibernate ORM 来处理基于 MySQL 的应用程序.我只是不明白为基于 MongoDB 的应用程序在两者之间选择哪个框架.

I have not used Spring Data before but I've used Hibernate ORM a number of times for MySQL based application. I just don't understand which framework to choose between the two for a MongoDB based application.

我已尝试寻找答案,但找不到在生产环境中对两者进行比较的答案.有没有人发现在 MongoDB 中使用这两个框架时遇到问题?

I've tried searching for the answer but I can't find the answer which does a comparison between the two in a production environment. Has anyone found problems working with these two frameworks with MongoDB ?

推荐答案

免责声明:我是 Spring Data 项目的负责人,所以我将主要介绍 Spring Data 方面的内容:

Disclaimer: I am the lead of the Spring Data project, so I'll mostly cover the Spring Data side of things here:

我认为这两个项目的核心区别在于 Hibernate OGM 团队选择将他们的工作集中在 JPA 上,而 Spring Data 团队明确没有.原因如下:

I think the core distinction between the two projects ist that the Hibernate OGM team chose to center their efforts around the JPA while the Spring Data team explicitly did not. The reasons are as follows:

  • JPA 本质上是一种关系 API.规范的前两句话指出,它是一个用于对象关系映射的 API.这也体现在 API 的核心主题中:它讨论了表、列、连接、事务.不一定可以转移到 NoSQL 世界的概念.
  • 您通常会选择 NoSQL 存储,因为它具有特殊特性(例如 MongoDB 上的地理空间查询,能够为 Neo4j 执行图遍历).JPA 中没有(也将)可用,因此无论如何您都需要提供专有扩展.
  • 更糟糕的是,如果假设用户像在 JPA 中定义的那样在 NoSQL 存储上工作,JPA 的一些概念只会将用户引导到错误的方向:应该如何在 MongoDB 之上合理地实现事务回滚?

因此,对于 Spring Data,我们选择为受支持的商店提供一致的编程模型,而不是试图将所有内容强制到一个过度抽象的 API 中:您将获得众所周知的模板实现,您将获得存储库抽象,它适用于所有商店,但让您利用商店特定的功能和概念.

So with Spring Data we chose to rather provide a consistent programming model for the supported stores but not try to force everything into a single over-abstracting API: you get the well-known template implementations, you get the repository abstraction, which works identical for all stores but let's you leverage store specific features and concepts.

这篇关于Spring Data MongoDB 和 Hibernate OGM for MongoDB 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆