Opinionated JPA with Querydsl

Opinionated JPA with Querydsl

Richard "Virgo" Richter
Buy on Leanpub

Table of Contents

Preface›

    I JPA Good Times, Bad Times›

    • 1. Good Parts
      • JPA is standard
      • Database independence
      • Natural SQL-Java type mapping
      • Flexible mapping
      • Unit of work
      • Declarative transactions
      • Other JPA 2.1 goodies
    • 2. The Missing Parts
      • Compared to ORM providers
      • Comparing JPQL to SQL
      • Other missing parts
    • 3. Questionable parts
      • Lazy on basic and to-one fields
      • Generated SQL updates
      • Unit of work vs queries
      • We can’t escape SQL and relational model
      • Additional layer
      • Big unit of work
      • Other entity manager gotchas
      • JPA alternatives?
    • 4. Caching considerations
      • Caching control
      • Second-level cache vs queries
      • Explicit application-level cache
      • Conclusion
    • 5. Love and hate for ORM
      • Vietnam of Computer Science
      • Not much love for ORM
      • But a lot of hate
      • Is tuning-down a way out?
      • And there is more

    II Opinionated JPA›

    • 6. Tuning ORM down
      • Price for relations
      • How does this affect my domain model?
      • When to tune down and when not?
    • 7. No further step without Querydsl
      • Simple example with Querydsl
      • Comparison with Criteria API
      • Comparison with JPQL
      • What about the cons?
      • Be explicit with aliases
      • Functions and operations
      • Subqueries
      • Pagination
      • Tuple results
      • Fetching to-many eagerly
      • Querydsl and code style
      • More
    • 8. Troubles with to-one relationships
      • Simple example of @ManyToOne
      • How about going lazy?
      • Dual relationship mapping
      • Using projections for fetching
      • Entity update scenario
      • Alternative entity “views”
      • Summary
    • 9. Removing to-one altogether
      • Why do we need ON anyway?
      • Dropping to-one annotations
      • Ad hoc joins across tables
      • Loading the relationship from the entity
      • Loosing information without mapping annotations
      • Wrapping it up
    • 10. Modularity, if you must
      • Everybody knows layers
      • Components based on features
      • Multiple JARs with JPA entities
      • Distributing persistence.xml – do we need it?
      • It doesn’t start anyway
      • Shared cache mode
      • Putting the Spring configuration together
      • Common base entity classes in separate JAR
      • Cutting cyclic dependencies
      • Conclusion

    III Common problems›

    • 11. Avoid N+1 select
      • Anatomy of N+1 select
      • Eager to-one without joins
      • Eager to-many relationships
      • Lazy relationships triggered later
      • Paginating with to-many
      • Wrapping up N+1 problem
    • 12. Mapping Java enum
      • Naive approach
      • Encapsulated conversion
      • Conversion micro-framework
      • Refinement?
      • Simplified static resolving
      • Alternative conversions within entities
      • Java 8 and reverse enum resolution
      • Relational concerns
    • 13. Advanced Querydsl
      • Introducing handy utility classes
      • Tricky predicate parts
      • Groups of AND/OR predicates
      • Operator precedence and expression serialization
      • Querydsl Expression hierarchy
      • Constant expressions
      • Using FUNCTION template
      • Update/delete clauses and exception handling
      • JPAQueryFactory
      • Detached queries
      • Working with dates and java.time API
      • Result transformation
      • Note about Querydsl 3 versus 4

    IV Final thoughts›

      Appendices›

      • H2 Database
        • Starting it
        • Using it as a devel/test DB
      • Project example
        • Querydsl and Maven
        • Querydsl and Gradle
      • Bugs discovered while writing this book
      • List of acronyms

      Resources›

        Notes›

          Opinionated JPA with Querydsl/