Hibernate / JPA / ORM
Hibernate is one of the most famous ORM framework. The purpose of ORM is let the developer to write cleaner domain logic.
But the drawback is the lack of type safety. The config to build the mapping is very annoying, The query tool (HQL or JPA criteria queries) is very verbose and hard to read.
To address the above issue, jOOQ is borned.
As side note, QueryDSL is also a good JPA based candidate to solve above issue.
jOOQ / JDBC / SQL
jOOQ help to use database schema to generate Java classes, avoid the normal ORM pattern.
config In the config, we put the jOOQ in as the required dependency, then link to related DB and tables. Also we need to indicate where will the generated targets be stored.
code gen
In the compile
phase, pojo classes will be generated for each table, then we can use the class to access DB schema in the type safe way.
usage Example:
Result<Record3<Integer, String, Integer>> result = dsl
.select(author.ID, author.LAST_NAME, DSL.count())
.from(author)
.join(authorBook)
.on(author.ID.equal(authorBook.AUTHOR_ID))
.join(book)
.on(authorBook.BOOK_ID.equal(book.ID))
.groupBy(author.LAST_NAME)
.fetch();
for detail check here
Benefits
-
write the query in SQLish syntax, the powerful querying helps you to have better control on data
-
compiler make sure the sql syntax correct and type safe, no more runtime error
-
code generation is efficient and make sure your code always sync with schema
Connection Pool According to the article Connection Pool, the smaller connection pool size is usually better than the big one.
Because too many thread/pool bring more overhead when the cpu switch the context.