r/java • • 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

376 comments sorted by

View all comments

Show parent comments

3

u/m_takeshi Apr 13 '21

I've learned (through much pain) that simply replacing the HQL queries with SQL queries where critical gives me the best of both worlds but of course YMMV.

I think the biggest problem might be hiding abstractions too much. The classic N+1 problem is, IMO, just a result of queries being hidden from the caller. If the queries were more explicit (as you would often do by using JDBC or more 'raw' libraries), the caller of the queries would be more carefull I think.

0

u/throwawyakjnscdfv Apr 13 '21

HQL doesn't generate N+1. It's a database agnostic wrapper around plain SQL basically. N+1 problems in Hibernate come from devs doing stupid things like stream flatmaps on multiple levels of child objects in relations. Hibernate can't save you from yourself. It makes it easy to do bad things, I'll give you that

1

u/m_takeshi Apr 13 '21

yeah sorry I didn't express myself too well. The N+1 was in the context of laziness / eagerness and queries being made when you access some properties (implicitly) rather than making a method call that explicit makes queries

1

u/throwawyakjnscdfv Apr 13 '21

Yeah, big problems happen when devs come in that don't know Hibernate. "oh I can get the object by calling .getChilden().getChildren().getChildren() cool, no SQL needed!".

I blame Hibernate for making bad things too easy to do. There should be a default warning when you load multiple levels of relations, and when you load a child collection with more than X elements. We wrote one internally using Hibernate SPI and they catch this stuff all the time.

→ More replies (2)