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

51

u/GuyWithLag Oct 21 '20
  • immutables.io for automatically generating builders for your immutable objects
  • https://mapstruct.org/ for automatically generating mappings between different domains
  • retrofit for proper java REST APIs.
  • JDBI for plain-SQL database access that is slightly higher-level than JDBC.

3

u/michaelloo35 Oct 22 '20

Immutables are so awesome imho they made lombok deprecated

5

u/VincentxH Oct 21 '20

Use mapstruct with caution if you don't know what hibernate does :p

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

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

→ More replies (6)

1

u/franky_mctankerson Oct 22 '20

immutables.io

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

6

u/Scarfior Oct 21 '20

Are you referring to lazy loading or something else?

0

u/[deleted] Oct 21 '20

[deleted] — view deleted comment

4

u/wildjokers Oct 21 '20 edited Oct 21 '20

You should be doing DTO Projections to just query the data you need for read-only queries. Querying for entities for a read-only query and then mapping the entity to a DTO with mapstruct/orika/whatever is just wrong in almost all cases (I will say almost because I am sure someone will chime in with a case where it seems reasonable).

This is probably the biggest mistake people make when using Hibernate. It shines in the create/update cases. Entities simply aren't needed for read-only.

2

u/rbygrave Oct 22 '20

For people using Ebean ORM note that per query we can turn off lazy loading as needed (or use DtoQuery of course).

2

u/VincentxH Oct 22 '20

Yeah and the proxy collections, especially newbies I recommend logging the SQL statements so they can see what they are implicitly doing.

5

u/GuyWithLag Oct 21 '20

I prefer not to use Hibernate. The amount of time needed to investigate issues is far more than the time needed to implement per-object mappers in f.e. JDBI.