Java AppEngine:JDO还是JPA,如何选择?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/994624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 14:43:54  来源:igfitidea点击:

Java AppEngine: JDO or JPA, How to choose?

javagoogle-app-enginegrailsjpajdo

提问by zotherstupidguy

Pros and Cons of choosing JDO or JPA for a Grails Application that will run on Google AppEngine

为将在 Google AppEngine 上运行的 Grails 应用程序选择 JDO 或 JPA 的利弊

回答by DataNucleus

I dosee why you would choose JDO. Don't know what is the "default" referred to by other poster. JDO is datastore-agnostic. JPA isn't. JDO allows fetch groups. JPA doesn't. JDO allows datastore identity. JPA doesn't. JDO allows datastore transactions. JPA doesn't. All of this is public record http://db.apache.org/jdo/jdo_v_jpa.html

明白你为什么会选择JDO。不知道其他海报提到的“默认”是什么。JDO 与数据存储无关。JPA 不是。JDO 允许获取组。JPA 没有。JDO 允许数据存储标识。JPA 没有。JDO 允许数据存储事务。JPA 没有。所有这些都是公共记录 http://db.apache.org/jdo/jdo_v_jpa.html

JDO and JPA don't fill the same problem space. They overlap only for RDBMS. JPA is only designed for RDBMS.JPA is not simpler, as evidenced by the API comparison at http://db.apache.org/jdo/jdo_v_jpa_api.html

JDO 和 JPA 不填充相同的问题空间。它们仅在 RDBMS 中重叠。JPA 仅为 RDBMS 设计。JPA 并不简单,正如http://db.apache.org/jdo/jdo_v_jpa_api.html 上的 API 比较所证明的那样

--Andy (DataNucleus)

--安迪(DataNucleus)

回答by icoloma

If you are building for AppEngine the road is shorter and there are less hiccups if you use JDO. Else, you will have a JPA layer around your JDO engine.

如果您正在为 AppEngine 构建,那么道路会更短,而且如果您使用 JDO,那么打嗝也会更少。否则,您的 JDO 引擎周围将有一个 JPA 层。

回答by Adeel Ansari

By the way, Grails have its data persistence build on top of Hibernate. How do you think JDO would help you in something Hibernate will not? I don't see why one would choose JDO over the default.

顺便说一下,Grails 的数据持久性建立在 Hibernate 之上。您认为 JDO 会如何帮助您解决 Hibernate 不会的问题?我不明白为什么人们会选择 JDO 而不是默认设置。

As far as JPA is concerned, I would recommend you to use JPA, Hibernate implementation of JPA which comes handy with Grails, and not any of the Hibernate specific feature, unless otherwise compelling.

就 JPA 而言,我建议您使用 JPA、JPA 的 Hibernate 实现,它在 Grails 中很方便,而不是任何 Hibernate 特定功能,除非另有说明。

[No more relevant after a significant change in question]

[在问题发生重大变化后不再相关]

Thats perfectly fine to have CRUD operations in your entity itself. But there are cases where you may find yourself operating over multiple entities, in that case a layer comes handy and clean, IMHO. Again, its the matter of requirement.

在您的实体中进行 CRUD 操作完全没问题。但是在某些情况下,您可能会发现自己在多个实体上进行操作,在这种情况下,恕我直言,层会变得方便和干净。再次,它的需求问题。

回答by Jon

[No longer relevant after a significant change in question]

[在问题发生重大变化后不再相关]

Take a look at the following articles:

看看以下文章:

http://www.infoq.com/news/2007/09/jpa-dao

http://www.infoq.com/news/2007/09/jpa-dao

Sounds like it really depends on the nature of your application and the size of it. JPA is simpler so I'd stick with that and try to avoid a DAO layer in your application, provided it's a fairly small and simple application.

听起来这真的取决于您的应用程序的性质和它的大小。JPA 更简单,所以我会坚持并尽量避免在您的应用程序中使用 DAO 层,前提是它是一个相当小而简单的应用程序。