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

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

问题描述

我以前没有使用过Spring Data,但是对于基于MySQL的应用程序,我已经多次使用过Hibernate ORM.对于基于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. spec状态的前两个句子表明,这是一个用于对象关系映射的API. API的核心主题也体现了这一点:它讨论表,列,联接,事务.不一定可以转移到NoSQL世界中的概念.
  • 您通常会选择NoSQL存储,因为它具有特殊的特征(例如,在MongoDB上进行地理空间查询,能够执行Neo4j的图形遍历).它们在JPA中都不可用(并且将可用),因此无论如何您都需要提供专有扩展.
  • 更糟糕的是,JPA的概念将使用户误以为如果假设他们像在JPA中定义的那样在NoSQL存储上工作,就会错误地引导用户:应该如何在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和用于MongoDB的Hibernate OGM有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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