Spring/Hibernate optimization: JPA with @OneToOne mapping

Lately I wanted to see how Hibernate actually construct sql statements. And it seems like it makes somtimes unnecessary joins. Those are my playground's results.

Repo: https://github.com/toficzak/social-app

Setup:

Post repository consists of 3 methods:


Sql generated by Hibernate:
How did I measure execution time:

  
Simple select measure

By author id: 1952090.938
By author (User provided): 1048579.671
By author (User not provided): 1021450.464
By custom query: 935087.347

My custom JPA query is the fastest option - it skips whole User join section. But why is it needed at all? Seems like an error in my design.

Komentarze

Popularne posty z tego bloga

Java EE 8 & Wildfly 17 & RestEasy setup

Testing: jUnit's TemporaryFolder

Two entities coexisting in one table