Java 休眠的替代方案

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

Alternatives to hibernate

javasqlhibernateorm

提问by dov.amir

What would be the best solution for programmers like http://vimeo.com/28885655

对于像http://vimeo.com/28885655这样的程序员来说,最好的解决方案是什么

The people who created the video believe

制作视频的人相信

  1. In many cases hibernate is overkill
  2. Basic sql is a good language that hibernate abstracts away to much
  1. 在许多情况下,休眠是矫枉过正的
  2. 基本的 sql 是一种很好的语言,它被 hibernate 抽象了很多

I heard about some other ORM implementations like

我听说过其他一些 ORM 实现,例如

I would like to hear how they compare and what are the advantages/disadvantages of each one.

我想听听他们如何比较以及每个人的优点/缺点是什么。

采纳答案by ?ukasz R?anek

Hereyou can find an extensive list of Java ORMs and persistence solutions. Not all of the follows Hibernate/JPAs approach, some of them are quite easy by design.

在这里您可以找到 Java ORM 和持久性解决方案的广泛列表。并非所有遵循 Hibernate/JPA 方法,其中一些在设计上非常简单。

Of course there are solutions not listed on that site, i.e. Spring JDBC with templates, etc.. And this is my personal choice for projects that require fast, easy to build JDBC access and are already using Spring.

当然也有网站上没有列出的解决方案,即带有模板的Spring JDBC等。对于需要快速、轻松构建 JDBC 访问并且已经在使用 Spring 的项目,这是我个人的选择。

In general, for me at least, it's a little bit to early to say Hibernate is bad and it grown to big. It serves it's purpose quite well, but grown to fit to many shoes. My personal opinion is that it will stay as it is, but NoSQL solutions will probably give birth to a new breed of Java data mapping solutions, like Spring Data. There is a need to create a simple approach to interact with application data, but I don't believe there is a consensus on how to get there... yet.

总的来说,至少对我来说,现在说 Hibernate 很糟糕并且它变得很大还为时过早。它很好地达到了它的目的,但已经适合许多鞋子。我个人的观点是它会保持原样,但 NoSQL 解决方案可能会催生一种新的 Java 数据映射解决方案,比如Spring Data。需要创建一种与应用程序数据交互的简单方法,但我不相信就如何实现这一点达成共识......

回答by ftr

If you want control over the used SQL and remain close to JDBC in general, you may be interested in MyBatis, which let's you write your own queries and provides a framework for "automatically" mapping ResultSets to POJOs based on XML- or annotation-based metadata.

如果你想控制使用的 SQL 并保持接近 JDBC,你可能对MyBatis感兴趣,它让你编写自己的查询并提供一个框架,用于基于 XML 或基于注解的“自动”映射 ResultSets 到 POJO元数据。

A select would look like this in XML:

一个选择在 XML 中看起来像这样:

<select id="selectUsers" parameterType="int" resultType="my.User">
 select id, username, password
 from users
 where id = #{id}
</select>

This would be mapped to a user like this:

这将映射到这样的用户:

<resultMap id="userResultMap" type="my.User">
   <id property="id" column="id" />
   <result property="username" column="user_name"/>
   <result property="password" column="hashed_password"/>
</resultMap>

With the properties being Bean properties in the POJO my.User

属性是 POJO my.User 中的 Bean 属性

回答by Jeff Miller

The presenter makes a good case that some frameworks are overly complicated. The vast number of ORM libraries seems to be an indicator that a good solution is elusive.

演示者很好地说明了某些框架过于复杂。大量的 ORM 库似乎表明一个好的解决方案是难以捉摸的。

Github, bitbucket, source forge have hundreds of ORM projects. Wikipediahas a good list too.

Github、bitbucket、source forge 有数百个 ORM 项目。维基百科也有一个很好的列表。

I invented sormulaas a lightweight alternative to complicated frameworks like JPA. See sormula sitefor a list of features and examples.

我发明了sormula作为 JPA 等复杂框架的轻量级替代品。有关功能和示例的列表,请参阅sormula 站点

It also contains a package that implements the active record pattern for those that like that approach but is not required.

它还包含一个包,该包为那些喜欢这种方法但不是必需的人实现了活动记录模式。