What Java ORM do you prefer, and why? [closed] What Java ORM do you prefer, and why? [closed] java java

What Java ORM do you prefer, and why? [closed]


I have stopped using ORMs.

The reason is not any great flaw in the concept. Hibernate works well. Instead, I have found that queries have low overhead and I can fit lots of complex logic into large SQL queries, and shift a lot of my processing into the database.

So consider just using the JDBC package.


None, because having an ORM takes too much control away with small benefits. The time savings gained are easily blown away when you have to debug abnormalities resulting from the use of the ORM. Furthermore, ORMs discourage developers from learning SQL and how relational databases work and using this for their benefit.


Many ORM's are great, you need to know why you want to add abstraction on top of JDBC. I can recommend http://www.jooq.org to you (disclaimer: I'm the creator of jOOQ, so this answer is biased). jOOQ embraces the following paradigm:

  • SQL is a good thing. Many things can be expressed quite nicely in SQL. There is no need for complete abstraction of SQL.
  • The relational data model is a good thing. It has proven the best data model for the last 40 years. There is no need for XML databases or truly object oriented data models. Instead, your company runs several instances of Oracle, MySQL, MSSQL, DB2 or any other RDBMS.
  • SQL has a structure and syntax. It should not be expressed using "low-level" String concatenation in JDBC - or "high-level" String concatenation in HQL - both of which are prone to hold syntax errors.
  • Variable binding tends to be very complex when dealing with major queries. THAT is something that should be abstracted.
  • POJO's are great when writing Java code manipulating database data.
  • POJO's are a pain to write and maintain manually. Code generation is the way to go. You will have compile-safe queries including datatype-safety.
  • The database comes first. While the application on top of your database may change over time, the database itself is probably going to last longer.
  • Yes, you do have stored procedures and user defined types (UDT's) in your legacy database. Your database-tool should support that.

There are many other good ORM's. Especially Hibernate or iBATIS have a great community. But if you're looking for an intuitive, simple one, I'll say give jOOQ a try. You'll love it! :-)

Check out this example SQL:

  // Select authors with books that are sold out  SELECT *     FROM T_AUTHOR a   WHERE EXISTS (SELECT 1                   FROM T_BOOK                  WHERE T_BOOK.STATUS = 'SOLD OUT'                    AND T_BOOK.AUTHOR_ID = a.ID);

And how it can be expressed in jOOQ:

  // Alias the author table  TAuthor a = T_AUTHOR.as("a");  // Use the aliased table in the select statement  create.selectFrom(a)        .whereExists(create.selectOne()                           .from(T_BOOK)                           .where(T_BOOK.STATUS.equal(TBookStatus.SOLD_OUT)                           .and(T_BOOK.AUTHOR_ID.equal(a.ID))))));