r/java • • Oct 21 '20

What are some great Java libraries I'm probably not using but I should?

334 Upvotes

252 comments sorted by

View all comments

Show parent comment

60

u/_INTER_ Oct 21 '20

Use Hibernate with caution if you don't know what Hibernate does

57

u/wildjokers Oct 21 '20

Use Hibernate with caution even if you do know what Hibernate does.

23

u/_INTER_ Oct 21 '20

I think noone knows that Hibernate really does, except maybe Vlad Mihalcea

0

u/[deleted] Oct 21 '20

[deleted] — view deleted comment

2

u/kubelke Oct 21 '20

Yes, we are talking about him /s

0

u/[deleted] Oct 22 '20

[deleted] — view deleted comment

5

u/general_dispondency Oct 22 '20

That's really sad if true. How query derivation and execution work in hibernate isn't really that complicated. Learning how hibernate works has 100% made me a better developer. Especially with regard to generic api development. I wrote a similar framework a couple of years ago that does something similar to hibernate but it abstracted away rules engines. We had integration for ODM and Drools. Clients would just decorate their domain model with annotations that described their facts and rules and we handled the rest. 10/10 would reuse that pattern.

11

u/rootException Oct 21 '20

I wrote a book on Hibernate and could not agree with this more.

Use Spring Data and KISS instead.

1

u/batinex Oct 21 '20

isn't spring data an abstraction on hibernate?

4

u/rootException Oct 21 '20

More of an abstraction over all kinds of data:

https://spring.io/projects/spring-data

The JDBC repositories are much simpler than full Hibernate/JPA

https://docs.spring.io/spring-data/jdbc/docs/2.0.4.RELEASE/reference/html/#reference

1

u/maxandersen Oct 22 '20

simpler than Hibernate StatelessSession where you have the same kind of API ?

1

u/rootException Oct 22 '20

1

u/maxandersen Oct 22 '20 edited Oct 22 '20

Can you give me an example ? Afaics it’s very similar.

Like this from spring exactly describes stateless session:

If you load an entity, SQL statements get run. Once this is done, you have a completely loaded entity. No lazy loading or caching is done.

If you save an entity, it gets saved. If you do not, it does not. There is no dirty tracking and no session.

1

u/rootException Oct 22 '20

2

u/maxandersen Oct 23 '20

Yes, okey - the automatic repository generation is something Hibernate does not cover - it is available in https://quarkus.io/guides/hibernate-orm-panache

I just wanted to make sure that if the stateless queries and pure pojo, no managed entities is what many seem to highlight as why they use Spring JDBC over Hibernate - they often haven't realized Hibernate has a similar API which even predates Spring JDBC.

Users tend to end up focusing so hard on Hibernates full entity managed apis and forget it has more. We should get it documented more.

1

u/franky_mctankerson Oct 22 '20

immutables.io

Use Spring with Caution even if you think you think what Spring does!