Java JPA 和 EBean Play 框架的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20836923/
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-08-13 04:41:57  来源:igfitidea点击:

Difference between JPA and EBean Play Framework

javajpaplayframeworkebean

提问by xxxo_tryme

I'm relatively new to Play framework, I tried following the cookbook but it seems to be already outdated. Anyways I just want to know if there's a big difference between those I have mentioned.

我对 Play 框架比较陌生,我尝试遵循食谱,但它似乎已经过时了。无论如何,我只想知道我提到的那些之间是否存在很大差异。

Some tutorials used eBean whilst the others used jpa. I am really confused.

一些教程使用 eBean,而其他教程使用 jpa。我真的很困惑。

回答by www.Decompiler.com

same question answered here: https://groups.google.com/forum/#!topic/play-framework/6OR1Osf4AAU

同样的问题在这里回答:https: //groups.google.com/forum/#!topic/play-framework/ 6OR1Osf4AAU

JPA is a standard which many libraries implement. Ebean uses parts of the JPA standard. Ebean expects you to annotate your models with JPA annotations. So the question, which is better, Ebean or JPA, is a strange one to answer since Ebean partially is a JPA implementation. I believe Play 2 might also offer a Hibernate integration, which more fully implements the JPA standard, and perhaps is what you were asking about? Hibernate is much more widely used in the Java community. I switched to Ebean when trying Play 2 and haven't looked back. I much prefer it to Hibernate because Hibernate had many tricky gotchas that I was always stumbling over and I haven't found any of these issues with ebean.

JPA 是许多库实现的标准。Ebean 使用部分 JPA 标准。Ebean 希望您使用 JPA 注释来注释模型。因此,Ebean 还是 JPA 更好的问题是一个奇怪的答案,因为 Ebean 部分是 JPA 实现。我相信 Play 2 也可能提供 Hibernate 集成,它更全面地实现了 JPA 标准,也许这就是您要问的?Hibernate 在 Java 社区中得到了更广泛的使用。我在尝试 Play 2 时切换到 Ebean 并且没有回头。与 Hibernate 相比,我更喜欢它,因为 Hibernate 有许多棘手的问题,我总是绊倒这些问题,而且我还没有在 ebean 上发现任何这些问题。

回答by Brian Porter

Well in Play 2.3 they will be switching back to JPA!! James Ward, Developer Advocate at Typesafe, just told me to start new projects with JPA: https://twitter.com/_JamesWard/status/416977192019456000(or specifically Hibernate)

好吧,在 Play 2.3 中,他们将切换回 JPA!Typesafe 的开发人员倡导者 James Ward 刚刚告诉我用 JPA 开始新项目:https: //twitter.com/_JamesWard/status/416977192019456000(或特别是 Hibernate)

Here is the official Roadmap for Play 2.3: https://docs.google.com/document/d/11sVi1-REAIDFVHvwBrfRt1uXkBzROHQYgmcZNGJtDnA/pub

以下是 Play 2.3 的官方路线图:https: //docs.google.com/document/d/11sVi1-REAIDFVHvwBrfRt1uXkBzROHQYgmcZNGJtDnA/pub

For some of the reasons behind the decision to switch back to JPA: "[2.3 Roadmap] - Question for DevTeam: Why is Ebean considered to be replaced with JPA in 2.3 ?" https://groups.google.com/forum/#!searchin/play-framework/2.3/play-framework/7pL-Gq_pj7M/UykJdAC6wyYJ

对于决定切换回 JPA 背后的一些原因:“[2.3 路线图] - DevTeam 的问题:为什么 Ebean 被认为在 2.3 中被 JPA 取代?” https://groups.google.com/forum/#!searchin/play-framework/2.3/play-framework/7pL-Gq_pj7M/UykJdAC6wyYJ

And finally, James Ward created a rudimentary Play JPA Example for me on github: https://github.com/jamesward/play-java-jpa

最后,James Ward 在 github 上为我创建了一个基本的 Play JPA 示例:https: //github.com/jamesward/play-java-jpa

It still needs to be enhanced with examples for searching and paging, but it is a start. I would appreciate hearing if anyone else finds a good best practice Play 2.3 JPA / Hibernate example.

它仍然需要通过搜索和分页示例进行增强,但这是一个开始。如果其他人找到了最佳实践 Play 2.3 JPA / Hibernate 示例,我将不胜感激。

回答by IanRae

EBean is simpler to use. Look at the sample app ComputerDatabase that comes with Play. You might want to use EBean while you are learning Play, since EBean is the current default.

EBean 使用起来更简单。查看 Play 附带的示例应用程序 ComputerDatabase。您可能想在学习 Play 时使用 EBean,因为 EBean 是当前的默认设置。

However, the future is JPA, so you might want to just take the plunge and learn it. There is a sample ComputerDatabaseJPA, that also comes with Play.

但是,未来是 JPA,因此您可能只想尝试一下并学习它。有一个示例 ComputerDatabaseJPA,它也随 Play 一起提供。

回答by Rob Bygrave

If you are interested in the more technical details around the difference between Ebean ORM and JPA (and Hibernate) and hence the reasons why Ebean exists in the first place you can have a look at:

如果您对 Ebean ORM 和 JPA(和 Hibernate)之间的差异的更多技术细节感兴趣,以及 Ebean 首先存在的原因,您可以查看:

http://ebean-orm.github.io/architecture/compare-jpa

http://ebean-orm.github.io/architecture/compare-jpa

In short there are 2 main issues:

简而言之,有两个主要问题:

  • Ebean ORM is "sessionless"ORM (so not attach/detach semantics, no EntityManger to manage etc)

  • Ebean ORM's query language is better designed to optimise Object graph construction (Support partial objectsand avoid N + 1- you should never have an N + 1 issue with Ebean no matter how complex the object graph).

  • Ebean ORM 是“无会话ORM(所以没有附加/分离语义,没有 EntityManger 来管理等)

  • Ebean ORM 的查询语言更好地设计用于优化对象图构建(支持部分对象避免 N + 1- 无论对象图多么复杂,Ebean 都不应该出现 N + 1 问题)。

For more details on Partial objects refer to:

有关 Partial 对象的更多详细信息,请参阅:

http://ebean-orm.github.io/docs/query/partialobjects

http://ebean-orm.github.io/docs/query/partialobjects

For more details on N + 1 refer to:

有关 N + 1 的更多详细信息,请参阅:

http://ebean-orm.github.io/docs/query/nplus1

http://ebean-orm.github.io/docs/query/nplus1