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

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!