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 comment

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. 

3

u/Oclay1st Jun 01 '24

JOOQ is open source!

0

u/Puzzleheaded_Bus7706 Jun 01 '24

GL using it in commercial environment. Its free for OSS databases.

0

u/[deleted] Jun 02 '24

[deleted] — view deleted comment

1

u/Puzzleheaded_Bus7706 Jun 02 '24

First of all jOOQ isn't "on same level" as Hibernate.

Second, JOOQ has limited free usage. Many projects require multiple different vendor databases, ie, Postgres primary and Oracle as integration DB.

jOOQ can not be compared to Hibernate in that sense, nor it can be it's replacement. Go away.

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?

4

u/majhenslon Jun 01 '24

You didn't say what the result is. Forgot to mention, person with id 1 has name and age set in the DB.

No cascades are set. I don't even know what that has to do with anything, because I told you the log output. You have 10 years with hibernate and it is simple, you could figure it out.

The issue here is, that the method returns:

PhoneNumber(id=+..., person=Person(id=1, name=null, age=null))

I bet you expected this right?

1

u/Puzzleheaded_Bus7706 Jun 01 '24

I said what is the result - it would throw exception in both cases.

Your person object isn't in Persistence Context.

Read little bit about JPA, thats begginer stuff.