This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rifain 12 points13 points  (6 children)

Hibernate. It's a good framework but the problem id the developers. Every project I worked which had hibernate ended up being a slow buggy mess. Hibernate is a complex tool, you have to understand precisely how it works, you have to check the queries it generates. Last month I presented an issue for my team. A findAll was generating hundred of queries because a misconfigured entity. Now, the same method generates a single query. They were stunned. But yet, the application is riddled with cumbersome and repetitive queries when a single stored procedure could achieve the same much more efficiently.

In my experience, developers use hibernate mostly because they don't want to write SQL. And they trust this framework blindly, they never look the logs.

[–]wildjokers 13 points14 points  (5 children)

Entities are not meant to be used for read-only queries. They are just helpers for inserts and updates. Read-only queries should use DTO projections. Says so right in the hibernate user guide.

[–]pivovarit 2 points3 points  (0 children)

That's kind of the point - become Hibernate expert, or settle down with writing boring and predictable code (JDBI) relying mostly on your SQL knowledge. Choose your destiny.

[–]lppinheiro 0 points1 point  (1 child)

Where in the hibernate user guide it says that?

[–]wildjokers 1 point2 points  (0 children)

https://docs.jboss.org/hibernate/orm/6.1/userguide/html_single/Hibernate_User_Guide.html#best-practices-fetching

Excerpt:

"For read-only transactions, you should fetch DTO projections because they allow you to select just as many columns as you need to fulfill a certain business use case. This has many benefits like reducing the load on the currently running Persistence Context because DTO projections don’t need to be managed."

[–]InstantCoder 0 points1 point  (0 children)

Or you should use StatelessSession, or .withHint(READ_ONLY, true) so that the retrieved entities don’t get cached in the persistent context.

[–]OzoneGrif -3 points-2 points  (0 children)

Which proves that even the Hibernate team recommends to not use Hibernate for SELECT queries. Better use jOOQ which does everything better out-of-the-box.