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

Show parent comments

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?

3

u/Puzzleheaded_Bus7706 Jun 01 '24

It depends if PhoneNumber entity cascades  Person entity persist. If it does, than exception is thrown, PK already exists. If it does not, different exception is thrown, because  Person isn't in PersistenceContext.

Whats the issue?

→ More replies (2)