Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Do you really need Hibernate?

Do you really need Hibernate?

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.

Using an example application, it is shown 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

Video


Resources

More Decks by Simon Martinelli

Other Decks in Programming

Transcript

  1. • 30 years of Software Engineering • Java for 25

    years • Self-employed since 2009 • University teacher for 18 years • JUG Switzerland, Location Bern About Me
  2. • 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 • Working with entity state transitions • Working with data set transformations • Neither approach is "the best" one! Both approaches are better suited to particular use cases JPA vs jOOQ
  3. • jOOQ assumes your database already exists • But it

    does not assume your database follows any rules imposed by jOOQ regarding the design Database First
  4. • jOOQ can be used in projects of any size

    • It was inspired by the requirements of software running on thousands of tables, views, and stored procedures. Queries there were so complex they generated up to 500 lines of Oracle execution plan • I’ve used jOOQ in an ERP product with • ~ 2000 Tables and Views • ~ 5000 Stored Procedures and Functions Does jOOQ scale?
  5. • 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 And now? Which one to use?
  6. Thank you! • Web martinelli.ch • EMail simon@martinelli.ch • Bluesky

    @martinelli.ch • LinkedIn https://linkedin.com/in/ simonmartinelli