$30 off During Our Annual Pro Sale. View Details »

Do you really need Hibernate?

Do you really need Hibernate?

Hibernate is often used without thinking twice. But is that the best solution in all cases? This talk shows another possibility that can lead to better performance in many cases.

Projects often use Java Persistence API (JPA) by default and, thus, mostly Hibernate. But do all applications need a comprehensive object/relational mapping (ORM) with all conceivable functions?

This talk examines the architecture of database-centric applications and discusses whether you always need an object graph for persistence.

An example application shows how pure SQL, with the help of jOOQ and (nested) Java Records, simplifies data access and how common ORM problems, such as the n+1 select problem, can be avoided. Finally, the possibility of combining jOOQ and JPA/Hibernate and thus using the best of both worlds is discussed.

Simon Martinelli

May 23, 2023
Tweet

More Decks by Simon Martinelli

Other Decks in Programming

Transcript

  1. About me 1972 1995 2000 2007 2009 2011 2012 2013

    2021 2022 2023 COBOL JSR-352 Java Batch JSR-354 Money/Currency
  2. JPA vs jOOQ • Most conceptual differences between JPA and

    jOOQ are not technology-specific, but a matter of how you think about your database interactions • There are two approaches 1. Working with entity state transitions 2. Working with data set transformations • Neither approach is "the best" one; both approaches are better suited to certain use cases
  3. Where to Start? • Example Project • https://github.com/simasch/jooq-examples • Official

    Documentation • https://jooq.org • jOOQ Demo • https://github.com/jOOQ/demo
  4. Database First • jOOQ assumes your database already exists •

    But it does not assume your database follows any rules imposed by jOOQ regarding the design
  5. And now? Which one to use? • jOOQs superpower •

    Querying • Reading nested objects • Calling functions/stored procedures • Bulk updates and deletes • JPAs superpower • Entity state transition • Cascading insert, update, delete, and orphan removal