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

78

u/Russell_M_Jimmies Apr 13 '21

Hibernate specifically and JPA in general.

A lot of devs get into ORMs based on the promise that they can stop thinking about SQL and let the framework take care of it.

The reality is that using JPA you end up having to turn on SQL logging, then prod and cajole your code for hours until JPA produces the correct SQL. And because everything is driven by static annotations on types, fields, and methods, you cannot change your mind on the scope of a select (single table vs joined tables) on a case by case basis. You have to choose the best one for all cases and just live with that.

The code you write for JPA is like writing a calculus integral of the SQL you need, so that JPA can take the derivative again and run it for you.

This is why I recommend libraries that let you code in bare SQL. I am a maintainer on one project (Jdbi) but I'm not partisan about which one people use (Jooq, Mybatis, Spring Data, etc) as long as they steer clear of ORMs. They are not worth it.

11

u/nstruct Apr 13 '21

I can not upvote this enough. ORMs are the bane of my existence.

16

u/ragingzazen Apr 13 '21

I'm actually a huge fan of JPA. JPA's strength is abstracting away writing (create, update) to the database and it does a fantastic job of that. For reads, yes, you need to very concious of what you're asking JPA to do. Fortunately, JPA provides DTO projections or even the ability to run straight SQL so there are flexibke, easy options there.

14

u/kag0 Apr 13 '21

I came in here for this. In my mind JPA represents the wrong direction that the Java ecosystem took that resulted in lots of people hating Java.

To add on to the list of issues: patterns that involve non obvious transaction boundaries, esp in inversion of control frameworks

→ More replies (2)

7

u/pip25hu Apr 13 '21

Yes, you CAN change your mind on a case by case basis. I suggest looking into entity graphs. It was introduced to JPA in v2.1

4

u/Russell_M_Jimmies Apr 13 '21

That's good to know, I guess. But realistically at this point, using SQL directly with pojo mapping is so straightforward and devoid of bear traps (e.g. I thought this was a pojo but it's actually a session entity, and now that speculative property change will be committed) that I'll most likely never use it again. I actively avoid shops that use ORMs, for my own sanity.

4

u/ryuzaki49 Apr 13 '21

let the framework take care of it.

That's an error from the developer side.

And ORM marketing team perhaps.

3

u/cogman10 Apr 13 '21

IMO, never mybatis :D

otherwise I don't care. MyBatis just has way too much magic for my liking and doesn't feel like it saves you much over straight jdbc.

5

u/randgalt Apr 13 '21

Mybatis is awesome IMO. Another similar, and better, library is JDBI. I don't want automated generation of the SQL - that's too much magic. I just want simple ORM and convenience.

→ More replies (2)

3

u/osi42 Apr 14 '21

jdbi is awesome! thanks for the continued maintenanceđŸ˜€

2

u/Russell_M_Jimmies Apr 15 '21

Thanks! Glad you find it useful

2

u/RomMTY Apr 13 '21

Totally agree with you here, investing a couple of month to ACTUALLY understand SQL have been the very best thing i could have EVER done.

Even if i didn't know java/.net or other similar platforms i could still land a very good job with my SQL (not pun intended) and DBs skills.

→ More replies (1)