31

When I chat to stackoverflowers on chat and read other tutorials about database with Java then they are guide me to use JOOQ instead of HIBERNATE.

I am totally aware about ORM with Hibernate and I prefer to use Hibernate and now aware almost about JOOQ by reading tutorials and implementation on small projects.

But I am confused what to choose and what is perfact for my dynamic web-applications which can be larger,medium or smaller, either Hibernate or JOOQ ?

BTW googled a lot but confused more and more...!!! Just Like : this,this and this.

Which one is best for different conditions and situations for developer.?

Community
  • 1
  • 1
Gopal00005
  • 2,061
  • 4
  • 35
  • 54

1 Answers1

40

While jOOQ and Hibernate compete for the same target audience, they do not solve the same problem at all. You've already linked this article in your question. The essence of it is simple:

  • Are you going to solve object graph persistence problems? Use an ORM (e.g. Hibernate)
  • Are you going to embed SQL into Java? Use SQL (e.g. jOOQ)

Of course, since both APIs cover accessing relational databases, they overlap in functionality to a certain extent. E.g. Hibernate also supports simple querying, while jOOQ also supports simple mapping.

While we should avoid delving into subjective discussions about whether object graph persistence or SQL is a better approach at interacting with your database, I think the above is a pretty objective answer to what API is better suited, once you've made the subjective decision.

AND: You can use both, e.g. ORM/Hibernate for CRUD, SQL/jOOQ for reporting.

(Disclaimer: I work for the company behind jOOQ, so this answer is biased)

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • 1
    Why do I have to use JOOQ for reporting please can you elaborate it more descriptively ? It will be much helpful to me. – Gopal00005 Apr 03 '15 at 11:47
  • 8
    Reporting takes advantage of a lot of advanced SQL features. Of course, you *could* still use Hibernate/HQL/JPQL, but your reports will be a lot slower, harder to maintain than if written in plain SQL... – Lukas Eder Apr 03 '15 at 17:46
  • 1
    Yep right @Lukas Eder sir, I had just created this question to be more clear about lots of confusions with JOOQ and Hibernate and now I am very happy with your answer **hope it will be helpful to other people too**. – Gopal00005 Apr 03 '15 at 22:34
  • 1
    Pricing may play a role in the decision making process as well. If you are working with a non-open source database (Oracle, MSFT, etc) you have to pay a $99 per developer yearly fee to use JOOQ. Whereas Hibernate has no such requirements. – justin.hughey Aug 14 '15 at 19:16
  • @justin.hughey: It certainly may, but usually not because of the price per se (e.g., compare the license to hourly rates). If you do an objective calculation considering the total cost of ownership of technology, you may or may not come to a much higher price for using Hibernate, depending on the project setup. – Lukas Eder Aug 14 '15 at 20:53
  • Project setup is a one time cost with occasional maintenance costs. A yearly per-developer fee is a guaranteed recurring cost (with growth potential tied to team size). From an objective cost analysis perspective which would you pick? I recognize that "efficiency gains" and other hypothetical improvements are potentially recognizable. But in the world of known (cost analysis) vs unknown (potential efficiency gains) most individuals will rely on the knowledge they see as certain (cost analysis) in making the decision. – justin.hughey Aug 17 '15 at 14:24
  • 4
    *"most individuals will rely on the knowledge they see as certain (cost analysis) in making the decision."* - The only certain thing here is that those individuals should read Daniel Kahneman's [*"Thinking Fast And Slow"](https://en.wikipedia.org/wiki/Thinking,_Fast_and_Slow). Kahneman impressively displays how our fear of "loss" ("cost") is biasing our decisions in very unfortunate ways. Also, by now, it is clear that we're no longer discussing concrete costs here, but trying to make points, which is a bit off-topic on for this Stack Overflow question. – Lukas Eder Aug 17 '15 at 17:07
  • I didn't get any... BUT it seem that both do exactly the same thing and they don't complete each other, so we have to use one. so if i use JPA i originaly drive from hibernate, and i can't work with simple model jOOQ Provide, which i only saw sample of them, and i'm not sure if still that was the case or if it is. but i saw they used it with a simple xml file, so can JPA do that?Which is better to go after a database like h2 and hsqldb or xml file?i want the client be able to maintain the file, at any cost, while with no requirment to install database service. and have track of db struct too.. – Hassan Faghihi Nov 16 '16 at 16:28
  • to be honest i'm comming from dot net world, and there's a SQL Server that do many things, and you know your data are safe, you can backup them, use them, and when it come to changes, EF migrate the change and try not to blow the exist data up, in other world there are hibernate and postgres or etc, while what i though about some such as H2 and hsql they are in memory, and their model recreate, or at last it's what i thought from people talk, and i'm not sure if i should trust them with data, or at somepoint, at some changes, they may blow the DB, and i can't even have manual access to fix – Hassan Faghihi Nov 16 '16 at 16:31