Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?
Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.
So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!
High-Performance Hibernate Tutorial
I’ve been using Hibernate for almost a decade and I admit it was not an easy journey. These tutorials are snippets from my High-Performance Java Persistence book, whose main goal is to show you how to make your data access layer run a high speeds.
This material is useful for both beginners and experienced developers, so enjoy reading it.
The best Tutorials on High-Performance Hibernate #Hibernate #Java #Tutorials #NewYearsResolution #Career https://t.co/wQNjz6kK24 pic.twitter.com/4wDmQYvswq
— Java (@java) January 1, 2019
Tips and Best Practices
- 20 years of Hibernate
- Java data access technology survey results
- Why and when you should use JPA
- The best way to prevent JPA and Hibernate performance issues
- JPA Association Fetching Validator
- A beginner’s guide to the high-performance-java-persistence GitHub repository
- A beginner’s guide to SQL injection and how you should prevent it
- The best way to handle time zones in a Java web application
- How to use database-specific or Hibernate-specific features without sacrificing portability
- How to store date, time, and timestamps in UTC time zone with JDBC and Hibernate
- How to use the Hibernate
Session
doWork
anddoReturningWork
methods
JPA and Hibernate Peformance Tuning
- 14 High-Performance Java Persistence tips
- How to detect JPA and Hibernate performance issues automatically using Hypersistence Optimizer
- 9 High-Performance Tips when using MySQL with JPA and Hibernate
- Tuning Spring Petclinic JPA and Hibernate configuration with Hypersistence Optimizer
- 9 High-Performance Tips when using PostgreSQL with JPA and Hibernate
- Hibernate Application Performance Tuning
- 9 High-Performance Tips when using Oracle with JPA and Hibernate
- Hibernate Query Performance Tuning
- Hibernate slow query log
- Spring Boot performance tuning
- Spring Boot performance monitoring
- Hibernate performance tuning tips
- How to detect the Hibernate N+1 query problem during testing
- JDBC Profiling with VisualVM
- The fastest way to update a table row when using Hibernate and Oracle
Bootstrapping
- A beginner’s guide to JPA persistence.xml file
- How to bootstrap Hibernate without the
persistence.xml
configuration file - How to bootstrap JPA programmatically without the
persistence.xml
configuration file - JDBC Driver Connection URL strings
- JDBC Driver Maven dependency list
- The best way to configure the Hibernate Dialect
- How to get access to database table metadata with Hibernate 5
- How to get the entity mapping to database table binding metadata from Hibernate
Schema Management
- Flyway Database Schema Migrations
- Hibernate hbm2ddl.auto schema generation
- The best way to validate the DDL schema with Spring and Hibernate
Mappings
Basic Types
- How to implement a custom basic type using Hibernate
UserType
- JPA AttributeConverter – A Beginner’s Guide
- How to map calculated properties with JPA and Hibernate
@Formula
annotation - How to map calculated properties with Hibernate
@Generated
annotation - How to emulate
@CreatedBy
and@LastModifiedBy
from Spring Data using the@GeneratorType
Hibernate annotation - How to map Date and Timestamp with JPA and Hibernate
- What’s new in JPA 2.2 – Java 8 Date and Time Types
- The best way to map a Java 1.8 Optional entity attribute with JPA and Hibernate
- The best way to map an Enum Type with JPA and Hibernate
- How to map a JPA entity to a View or SQL query using Hibernate
- How to map the PostgreSQL inet type with JPA and Hibernate
- How to map a PostgreSQL Range column type with JPA and Hibernate
- How to map the Java YearMonth type with JPA and Hibernate
- How to map
java.time.Year
andjava.time.Month
with JPA and Hibernate - How to map a PostgreSQL Interval to a Java
Duration
with Hibernate - The best way to map
MonetaryAmount
with JPA and Hibernate - How to escape SQL reserved keywords with JPA and Hibernate
JSON
- How to map JSON objects using generic Hibernate Types
- How to map a String JPA property to a JSON column using Hibernate
- How to map a Jackson
JsonNode
to a JSON column - How to map JSON collections using JPA and Hibernate
- How to map a Java Map entity property as a JSON column with JPA and Hibernate
- How to map Java Records to JSON columns using Hibernate
- How to map polymorphic JSON objects with JPA and Hibernate
- How to encrypt and decrypt JSON properties with JPA and Hibernate
- Why you should use Hibernate Dynamic Update for JSON properties
- How to map Oracle JSON columns using JPA and Hibernate
- How to map SQL Server JSON columns using JPA and Hibernate
- How to customize the Hypersistence Utils Jackson ObjectMapper
- How to customize the Hypersistence Utils JSON Serializer
- How to fix the Hibernate “No Dialect mapping for JDBC type” issue
- How to fix the Hibernate “column is of type jsonb but expression is of type bytes” issue
ARRAY
- How to map a PostgreSQL ARRAY to a Java List with JPA and Hibernate
- How to map Java and SQL arrays with JPA and Hibernate
- How to map a PostgreSQL Enum ARRAY to a JPA entity property using Hibernate
- Multidimensional array mapping with JPA and Hibernate
- Hibernate HSQLDB ARRAY Type
Equals and HashCode
- The best way to implement equals, hashCode, and toString with JPA and Hibernate
- How to implement equals and hashCode using the entity identifier (primary key)
- How to implement equals and hashCode using the entity natural identifier
Relationships
- A beginner’s guide to database table relationships
- ManyToOne JPA and Hibernate association best practices
- The best way to map a @OneToOne relationship with JPA and Hibernate
- How to change the @OneToOne shared primary key column name with JPA and Hibernate
- The best way to use one-to-one table relationships
- The best way to map a @OneToMany relationship with JPA and Hibernate
- The best way to use the @ManyToMany annotation with JPA and Hibernate
- The best way to map a many-to-many association with extra columns when using JPA and Hibernate
- The best way to map a Composite Primary Key with JPA and Hibernate
- How to map a composite identifier using an automatically @GeneratedValue with JPA and Hibernate
- How to synchronize bidirectional entity associations with JPA and Hibernate
- The best way to use JPA bidirectional sync methods
- How to map a @ManyToOne association using a non-Primary Key column
- How to customize an entity association JOIN ON clause with Hibernate
@JoinFormula
- How to map a JPA
@ManyToOne
relationship to a SQL query using the Hibernate@JoinFormula
annotation - How to optimize unidirectional collections with JPA and Hibernate
- How do Set and List collections behave with JPA and Hibernate
Naming strategy
- Hibernate Physical Naming Strategy
- How to map camelCase properties to snake_case column names with Hibernate
Advanced mapping techniques
- Fluent API entity building with JPA and Hibernate
- How to map an immutable entity with JPA and Hibernate
- How to map the latest child of a parent entity using Hibernate
@JoinFormula
- How to map multiple JPA entities to one database table with Hibernate
- How to update only a subset of entity attributes using JPA and Hibernate @DynamicUpdate
- How to use external XML mappings files with JPA and Hibernate
- How to encrypt and decrypt data with Hibernate
- The best way to soft delete with Hibernate
- Soft delete and JPA version property
- How to fix “wrong column type encountered” schema-validation errors with JPA and Hibernate
- How to audit entity modifications using the JPA
@EntityListeners
,@Embedded
, and@Embeddable
annotations - How to use
@PrePersist
and@PreUpdate
on Embeddable with JPA and Hibernate
Identifiers
- Hibernate default entity sequence
- A beginner’s guide to natural and surrogate database keys
- Hibernate Identity, Sequence, and Table (Sequence) generator
- How to generate JPA entity identifier values using a database sequence
- The best way to generate a TSID entity identifier with JPA and Hibernate
- Hibernate Batch Sequence Generator
- The hi/lo algorithm
- Hibernate pooled and pooled-lo identifier generators
- A beginner’s guide to Hibernate enhanced identifier generators
- How to migrate the hilo Hibernate identifier optimizer to the pooled strategy
- Why you should never use the TABLE identifier generator with JPA and Hibernate
- Why should not use the AUTO JPA GenerationType with MySQL and Hibernate
- How to replace the TABLE identifier generator with either SEQUENCE or IDENTITY in a portable way
- PostgreSQL SERIAL column and Hibernate IDENTITY generator
- How to combine the Hibernate assigned generator with a sequence or an identity column
- How to implement a custom String-based sequence identifier generator with Hibernate
- MariaDB 10.3 supports database sequences
- Hibernate and UUID identifiers
- How to use a JVM or database auto-generated UUID identifier with JPA and Hibernate
- The best way to map a @NaturalId business key with JPA and Hibernate
Inheritance
- The best way to use entity inheritance with JPA and Hibernate
- The best way to map the SINGLE_TABLE inheritance with JPA and Hibernate
- MySQL 8 support for custom SQL CHECK constraints simplifies SINGLE_TABLE inheritance data integrity validation rules
- The best way to map the @DiscriminatorColumn with JPA and Hibernate
- How to inherit properties from a base class entity using
@MappedSuperclass
with JPA and Hibernate - How to order entity subclasses by their class type using JPA and Hibernate
Connection Management
- The simple scalability equation
- Maximum number of database connections
- The anatomy of Connection Pooling
- Why you should use FlexyPool
- How to monitor your connection pool with FlexyPool
- How to monitor a Java EE DataSource
- Why you should always use hibernate.connection.provider_disables_autocommit for resource-local JPA transactions
- How does aggressive connection release work in Hibernate
Persistence Context
- The JPA and Hibernate first-level cache
- A beginner’s guide to JPA/Hibernate entity state transitions
- A beginner’s guide to JPA and Hibernate Cascade Types
- How does orphanRemoval work with JPA and Hibernate
- A beginner’s guide to flush strategies in JPA and Hibernate
- How does persist and merge work in JPA
- How do JPA persist, merge and Hibernate save, update, saveOrUpdate work
- How to merge entity collections with JPA and Hibernate
- How does AUTO flush strategy work in Hibernate
- How to override the default Hibernate Session FlushMode
- How do JPA and Hibernate define the AUTO flush mode
- A beginner’s guide to Hibernate flush operation order
- The best way to clone or duplicate an entity with JPA and Hibernate
- How to intercept entity changes with Hibernate event listeners
- The anatomy of Hibernate dirty checking mechanism
- How to customize Hibernate dirty checking mechanism
Fetching
- Pagination best practices
- SQL Seek Method or Keyset Pagination
- Keyset Pagination with JPA and Hibernate
- JPA Default Fetch Plan
- JPA Entity Graph
- How do
find
andgetReference
EntityManager
methods work when using JPA and Hibernate - N+1 query problem with JPA and Hibernate
- The best way to fetch multiple entities by id using JPA and Hibernate
- A beginner’s guide to Hibernate fetching strategies
- EAGER fetching is a code smell
- The best way to map a projection query to a DTO (Data Transfer Object) with JPA and Hibernate
- How to write a compact DTO projection query with JPA
- How to fetch a one-to-many DTO projection with JPA and Hibernate
- The best way to handle the LazyInitializationException
- The best way to lazy load entity attributes using JPA and Hibernate
- Hibernate LazyToOne annotation
- The best way to initialize LAZY entity and collection proxies with JPA and Hibernate
- Why you should avoid EXTRA Lazy Collections with Hibernate
- ResultSet statement fetching with JDBC and Hibernate
- The best way to fix the Hibernate
MultipleBagFetchException
- How to fetch multiple JPA collections with Blaze Persistence MULTISET
- How to fetch entities multiple levels deep with Hibernate
- The Open Session In View Anti-Pattern
- The hibernate.enable_lazy_load_no_trans Anti-Pattern
- How does MySQL result set streaming perform vs fetching the whole JDBC ResultSet at once
- How does a JPA Proxy work and how to unproxy it with Hibernate
- The best way to fix the Hibernate “HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!” warning message
- How to detect HHH000104 issues with the
hibernate.query.fail_on_pagination_over_collection_fetch
configuration property
Bytecode Enhancement
- Maven and Gradle Hibernate Enhance Plugin
- How to enable bytecode enhancement dirty checking in Hibernate
- How does the bytecode enhancement dirty checking mechanism work in Hibernate 4.3
Concurrency Control
- The race condition that led to Flexcoin bankruptcy
- Data knowledge stack
- A beginner’s guide to ACID and database transactions
- Optimistc vs. Pessimistic Locking
- A beginner’s guide to database deadlock
- How does the 2PL (Two-Phase Locking) algorithm work
- How does MVCC (Multi-Version Concurrency Control) work
- How to get the current database transaction id
- How to log the database transaction id using MDC (Mapped Diagnostic Context)
- How does the entity version property work when merging with JPA and Hibernate
- Optimistic locking version property with JPA and Hibernate
- The best way to map an entity version property with JPA and Hibernate
- How do PostgreSQL advisory locks work
- How to implement a database job queue using SKIP LOCKED
- The best way to use SQL NOWAIT
- A beginner’s guide to database locking and the lost update phenomena
- How to prevent lost updates in long conversations
- A beginner’s guide to Dirty Read anomaly
- A beginner’s guide to Non-Repeatable Read anomaly
- A beginner’s guide to Phantom Read anomaly
- A beginner’s guide to Read and Write Skew phenomena
- A beginner’s guide to Serializability
- A beginner’s guide to the Write Skew anomaly, and how it differs between 2PL and MVCC
- How does database pessimistic locking interact with INSERT, UPDATE, and DELETE SQL statements
- How do UPSERT and MERGE work in Oracle, SQL Server, PostgreSQL, and MySQL
- Logical vs physical clock optimistic locking
- How to retry JPA transactions after an OptimisticLockException
- How does Hibernate guarantee application-level repeatable reads
- Hibernate collections optimistic locking
- How to address the OptimisticLockException in JPA and Hibernate
- How to prevent OptimisticLockException with Hibernate versionless optimistic locking
- A beginner’s guide to transaction isolation levels in enterprise Java
- A beginner’s guide to Java Persistence locking
- How does LockModeType.OPTIMISTIC work in JPA and Hibernate
- How to fix optimistic locking race conditions with pessimistic locking
- How does LockModeType.OPTIMISTIC_FORCE_INCREMENT work in JPA and Hibernate
- How does LockModeType.PESSIMISTIC_FORCE_INCREMENT work in JPA and Hibernate
- How do LockModeType.PESSIMISTIC_READ and LockModeType.PESSIMISTIC_WRITE work in JPA and Hibernate
- How does CascadeType.LOCK works in JPA and Hibernate
- How to increment the parent entity version whenever a child entity gets modified with JPA and Hibernate
- Spring read-only transaction Hibernate optimization
- Read-write and read-only transaction routing with Spring
- How does SQL Server Foreign Key Locking and the Hibernate
@DynamicUpdate
- Strong Consistency with YugabyteDB
Batching
- Batch processing best practices
- The best way to do batch processing with JPA and Hibernate
- How to batch INSERT and UPDATE statements with Hibernate
- How to batch DELETE statements with Hibernate
- How to customize the JDBC batch size for each Persistence Context with Hibernate
- How to find which statement failed in a JDBC Batch Update
- How to optimize the merge operation using update while batching with JPA and Hibernate
- How to enable multi-row inserts with the PostgreSQL
reWriteBatchedInserts
configuration property - How to enable multi-row inserts with the MySQL
rewriteBatchedStatements
configuration property - How to enable multi-row inserts with SQL Server
useBulkCopyForBatchInsert
configuration property
Queries
- Hibernate SQM – Semantic Query Model
- A beginner’s guide to JPA and Hibernate
Query
setParameter
method - A beginner’s guide to JPA and Hibernate query hints
- Hibernate and JPQL Window Functions
- The best way to use UNION, INTERSECT, and EXCEPT with Hibernate
- Query timeout with JPA and Hibernate
- The best way to use the JPA SqlResultSetMapping
- How to return a Map result from a JPA or Hibernate query
- How to write EXISTS subqueries with JPA and Hibernate
- How to improve statement caching efficiency with IN clause parameter padding
- A beginner’s guide to the Hibernate JPQL and Native Query Plan Cache
- How to optimize JPQL and Criteria API query plans with Hibernate Statistics
- How to intercept and modify SQL queries with the Hibernate StatementInspector
- The best way to use the JPQL DISTINCT keyword with JPA and Hibernate
- How to JOIN unrelated entities with JPA and Hibernate
- How to resolve the Hibernate global database schema and catalog for native SQL queries
- How to map table rows to columns using SQL PIVOT or CASE expressions
- The JPA EntityManager createNativeQuery is a Magic Wand
- The best way to use the Hibernate TupleTransformer
- Why you should use the Hibernate ResultTransformer to customize result set mappings
- The best way to use a Hibernate ResultTransformer
- Why you should definitely learn SQL Window Functions
- Query pagination with JPA and Hibernate
- What’s new in JPA 2.2 – Stream the result of a Query execution
- How to get the actual execution plan for an Oracle SQL query using Hibernate query hints
- How to solve the PostgreSQL :: cast operator issue with JPA and Hibernate
- How to execute SQL functions with multiple parameters in a JPQL query with Hibernate
- How to query parent rows when all children must match the filtering criteria with SQL and Hibernate
- How to bind custom Hibernate parameter types to JPA queries
Statement Caching
- How does a relational database execute SQL statements and prepared statements
- PostgreSQL JDBC Statement Caching
- MySQL JDBC Statement Caching
Bulk Processing
- Bulk Update and Delete with JPA and Hibernate
- JPA Criteria API Bulk Update and Delete
- Bulk Update optimistic locking with JPA and Hibernate
Criteria Queries
- Blaze Persistence – the best way to write JPA Criteria queries
- JPA Bulk Update and Delete with Blaze Persistence
- How to write JPA Criteria API queries using Codota
- JPA Criteria Metamodel Generation and Usage Guide
- How to query by entity type using JPA Criteria API
- Why you should always check the SQL statements generated by Criteria API
- The best way to use SQL functions in JPQL or Criteria API queries with JPA and Hibernate
- The performance penalty of Class.forName when parsing JPQL and Criteria queries
- How does Hibernate handle JPA Criteria API literals
Stored Procedures
- The best way to call a stored procedure with JPA and Hibernate
- How to call Oracle stored procedures and functions with JPA and Hibernate
- How to call SQL Server stored procedures and functions with JPA and Hibernate
- How to call PostgreSQL functions (stored procedures) with JPA and Hibernate
- How to call MySQL stored procedures and functions with JPA and Hibernate
Caching
- The JPA and Hibernate second-level cache
- A beginner’s guide to Cache synchronization strategies
- Things to consider before jumping to enterprise caching
- Caching best practices
- How does Hibernate store second-level cache entries
- How does Hibernate READ_ONLY CacheConcurrencyStrategy work
- How does Hibernate NONSTRICT_READ_WRITE CacheConcurrencyStrategy work
- How does Hibernate READ_WRITE CacheConcurrencyStrategy work
- How does Hibernate TRANSACTIONAL CacheConcurrencyStrategy work
- How does Hibernate Collection Cache work
- How does Hibernate Query Cache work
- How to use the Hibernate Query Cache for DTO projections
- How to avoid the Hibernate Query Cache N+1 issue
- How to cache non-existing entity fetch results with JPA and Hibernate
Logging
Statistics
Audit Logging
- A beginner’s guide to CDC (Change Data Capture)
- MySQL audit logging using triggers
- The best way to implement an audit log using Hibernate Envers
- How to extract change data events from MySQL to Kafka using Debezium
Multitenancy
- A beginner’s guide to database multitenancy
- Hibernate database catalog multitenancy
- Hibernate database schema multitenancy
Testing
- Testcontainers Database Integration Testing
- Hibernate integration testing strategies
- How to run database integration tests 20 times faster
- How to run integration tests at warp-speed using Docker and tmpfs
- The best way to detect database connection leaks
- How to install DB2 Express-C on Docker and set up the JDBC connection properties
- How to get started with CockroachDB and Hibernate
I'm running an online workshop on the 11th of October about High-Performance SQL.If you enjoyed this article, I bet you are going to love my Book and Video Courses as well.
