当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Alternatives to hibernate

问题描述:

What would be the best solution for programmers like 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

I heard about some other ORM implementations like

  • https://github.com/rufiao/persist
  • http://ormlite.com/
  • http://www.simpleorm.org/

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

网友答案:

Here you 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.

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.

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.

网友答案:

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.

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

I invented sormula as a lightweight alternative to complicated frameworks like JPA. See sormula site for a list of features and examples.

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

网友答案:

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.

A select would look like this in 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

分享给朋友:
您可能感兴趣的文章:
随机阅读: