r/java • • Jun 01 '24

What java technology (library, framework, feature) would not recommend and why?

165 Upvotes

464 comments sorted by

View all comments

129

u/majhenslon Jun 01 '24

Hibernate/JPA and anything on to of it, if you are not doing the most basic CRUD or are really experienced with it (are not using it as a crutch for interacting with the DB), because there are so many foot guns that would just be avoided by writing raw SQL.

-7

u/Puzzleheaded_Bus7706 Jun 01 '24

This is just pure bullshit. Hibernate is super easy and super useful!

Learn how to use it,  its simple 

3

u/OzoneGrif Jun 01 '24

jOOQ is also super easy but without all the horrendous magic Hibernate generates dynamically at runtime.

4

u/Puzzleheaded_Bus7706 Jun 01 '24

Magic? There is no magic in software. I'm yet to hear why hibernate is 'bad'

JOOQ is proprietary, JPA isn't. 

4

u/majhenslon Jun 01 '24

It is magic :)

// Person(id, name, age) is the constructor, person with id 1 is already in the DB
var phoneNumber = new PhoneNumber("+111111111", new Person(1, null, null));
em.persist(phoneNumber);
return em.createQuery("SELECT pn FROM PhoneNumber INNER JOIN Person p WHERE pn.id = :id, PhoneNumber.class)
  .setParameter("id", phoneNumber.id)
  .getSingleResult();

Logs:

insert into phone_number (phone_number, person_id) values (...)
select ... from phone_number pn inner join person p on p.id = pn.person_id

What is the result?

→ More replies (3)