-
“More than half of application performance bottlenecks originate in the database - http://www.appdynamics.com/database/
-
“Like us, our users place a lot of value in speed — that's why we've decided to take site speed into account in our search rankings.” Google Ranking
-
“It has been reported that every 100ms of latency costs Amazon 1% of profit." http://radar.oreilly.com/2008/08/radar-theme-web-ops.html
-
JPA is only a specification. It describes the interfaces that the client operates with and the standard object-relational mapping metadata (annotations, XML).
-
Although it implements the JPA specification, Hibernate retains its native API for both backward compatibility and to accommodate non-standard features.
First off all, we need to create a Postgres database with the name hibernate-tunings
in the port 5432
.
For example, we can use Docker to create that resource:
docker run --name hibernate-tunings \
-p 5432:5432 \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgresdemos \
-v $(pwd)"/hibernate-tunings:/var/lib/postgresql/data" -d postgres:11.4
Or, simply run the docker-compose up command, which will raise a database and run the migrations for us:
docker-compose up
To run all modules in a single command, we can execute:
mvn flyway:migrate -pl database-migrations \
-Dflyway.configFiles=local.conf \
-Dflyway.locations=filesystem:database-migrations/migration \
&& mvn clean install -pl helpers \
&& mvn clean package
- Run the migrations:
mvn flyway:migrate -pl database-migrations \
-Dflyway.configFiles=local.conf \
-Dflyway.locations=filesystem:database-migrations/migration
Or, in alternative:
cd database-migrations
mvn flyway:migrate -Dflyway.configFiles=local.conf
- build and run all the examples.
mvn clean install -pl helpers && mvn clean package
-
Get-Started
-
Connections
-
Types
-
Identifiers
-
JPA Relationships Types
-
Inheritance
- SingleTable About
- DiscriminatorColumn
- JoinedInheritance with JoinTable
-
Persistence Context and Flushing
- all the examples can be found in the module
advanced-topics
in the package:io.costax.hibernatetunning.persistencecontext
- all the examples can be found in the module
-
Batching
-
Cache
- 1st and 2nd level and query caches
- 1st level (Persistence Context)
- 2nd Level
- Query cache
- 2nd level cache in JavaEE Application Server Example with infinispan (cache2ndee project)
- 1st and 2nd level and query caches
-
Bulk Operations
-
Batching of write operations
-
Concurrency
- Concurrency About
- Isolation Issues
- Pessimistic Locking
LockModeType.PESSIMISTIC_READ
LockModeType.PESSIMISTIC_WRITE
- Optimistic-locking
@Version
- Force Version Increment
- Timeout:
javax.persistence.lock.timeout
- Deadlocks
-
Fetching
-
Tips
-
How to map a JPA entity to a View or SQL query using Hibernate
-
How to intercept entity changes with hibernate event listeners
-
How to use windows functions to optimise pagination
- Fix
HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!
- Fix
-
Enabling the hibernate.query.fail_on_pagination_over_collection_fetch configuration
- Since Hibernate ORM 5.2.13, you can now enable the hibernate.query.fail_on_pagination_over_collection_fetch configuration property as follows:
- Using JPA property
<property name="hibernate.query.fail_on_pagination_over_collection_fetch" value="true"/>
-
Hibernate maven enhance plugin - enable Lazy Initialization
- Fix
N + 1
problem withhibernate-enhance-plugin
- Impacts of enhance plugin on
@ManyToOne
relationship when this is marked withfetch=LAZY
- Fix
-
How to exclude distinct keyword from the generated JPQL and Criteria Queries
-
How to use bytecode enhancement dirty checking with hibernate-enhance-maven-plugin
-
How to use NotFound hibernate annotation, Action to do when an element is not found on a association
-
How to Join @ManyToOne of multiple subtypes in multiple collections in the same entity
-
How to implement a Hibernate ResultTransformer in JPA Criteria Query
-
How logging Hibernate slow query
<property name="hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS" value="25"/>
-
How to keep Order in a Collections using javax.persistence.OrderColumn - JPA annotation
-
How to implement override value of the defined generator strategy
-
How to implement a custom application GenericGenerator for complex Identifiers
-
When and why JPA entities should implement the Serializable interface
-
How to Handle NULL Values while Ordering Query Results in JPQL (NULLS FIRST or NULLS LAST)
-
How to override @GeneratedValue strategy with @GenericGenerator annotation
- The defined business id it is used instead, instead of the value provides by @GeneratedValue.
- The @GeneratedValue implementation should not be executed if the business identifier has already defined.
-
How to Map properties with database transformations using @ColumnTransformer hibernate annotation
-
Hibernate SortNatural and SortComparator annotations