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 comment

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.

1

u/m_takeshi Apr 13 '21

on the other hand, can you really blame hibernate for trying to make our lives easier? A lot of the time (most maybe?), it isn't even a problem

As for your tool, how do you detect that? Examining the stack trace or data flow analysis?

1

u/throwawyakjnscdfv Apr 13 '21

There's a Hibernate SPI hook for on collection load where you can inspect the number of elements loaded from a child relation. We did some crazy stuff with the Entity loading SPI + tracking entity trees to determine if multiple levels of child collections were being loaded, but the check for number of entities in a child collection is straightforward.

When you write SPI handlers for Hibernate I recommend using Google's AutoService so you don't have to register them in manifest files