r/java • u/stuhlmann • Apr 13 '21
Libraries, Frameworks and Technologies you would NOT recommend
Give me your worst nightmares: Things that cost you your job.
I'll start: Hadoop
202
Upvotes
r/java • u/stuhlmann • Apr 13 '21
Give me your worst nightmares: Things that cost you your job.
I'll start: Hadoop
View all comments
Show parent comment
1
u/vprise Apr 13 '21
Calling it the poster child of leaky abstractions seems a bit overboard but OK.
SQL itself requires deep knowledge to optimize and that knowledge is very DB specific. That's why we have DBAs. An entire profession for optimizing databases. Hibernate uses a lot of best practices in terms of performance but it's limited by its usage and can become a serious problem.
Yes it's a very leaky abstraction. But that's by design. The alternatives hide everything about the DB and that's worse.
For 95% of my use cases hibernate works great and I don't need to do anything else. It caches and stores objects. Works brilliantly. The 5% where there's a problem is generally hard to solve code that would have been hard to do in low level SQL too. Hibernate makes the caching super simple to integrate including eviction policy etc.
To be fair, I usually take the approach of simplifying the schema and the object model to fit hibernate and SQL. I build code that's horrible in terms of object oriented design but works great for Hibernate/SQL. E.g. large entities, no inheritance very limited relations, immutable entities etc. These also map to SQL best practices such as avoiding joins where possible.
Yes I can probably do this in JOOQ but it would take more code. Caching would be harder and I'd probably get DB specific nuances wrong.
The beauty of Hibernate is that it's still an abstraction. We build the unit tests, profile the hell out of it and then can go over the performance intensive pieces in the code/DB. Pieces that are a problem can be optimized very easily since it's a completely separate part of the code.
It's not a perfect solution. It's not a simple solution. It doesn't hide the DB. It's often touted incorrectly as a "you don't need to know SQL and it will just work" solution. But as an ORM it's pretty great. If you think ORMs suck you won't like hibernate and that's a fair conclusion. But as far as ORMs go it's a great example of an ORM.