How to enable bytecode enhancement dirty checking in Hibernate

Introduction

Hibernate runs the automatic dirty checking mechanism during flush-time, and any managed entity state change is translated into an UPDATE SQL statement. The default dirty checking mechanism uses Java reflection and goes through every property of every managed entity.

If the Persistence Context has few entities, this process might go unnoticed, but, if we’re dealing with many entities or the entities have many properties (e.g. a legacy database Domain Model mapping), then the reflection-based dirty checking might have an associated performance impact.

Continue reading “How to enable bytecode enhancement dirty checking in Hibernate”

High-Performance Java Persistence – Chapter 12 – Inheritance

Part 2, Chapter 12

Every new chapter of my book is released right after it’s being completed, so the reader doesn’t have to wait for the whole part to be finished to get access to new material.

Table of content

This chapter explains JPA inheritance from a data access performance point of view.

12. Inheritance
12.1 Single table 
12.2 Join table 
12.3 Table-per-class 
12.4 Mapped superclass 

Continue reading “High-Performance Java Persistence – Chapter 12 – Inheritance”

How does JPA and Hibernate define the AUTO flush mode

Introduction

The Persistence Context acts as a transactional-write behind cache for the incoming entity state transitions, and all changes are synchronized with the database during flushing.

Although both the Hibernate Session and the JPA EntityManager define a flush() method to manually trigger this process, it’s much more convenient to let Hibernate manage the Persistence Context flushing. Unfortunately, there’s is a major difference between how JPA and Hibernate define the automatic flushing mechanism.

Continue reading “How does JPA and Hibernate define the AUTO flush mode”

High-Performance Java Persistence – Chapter 11 – Relationships

Part 2, Chapter 11

Every new chapter of my book is released right after it’s being completed, so the reader doesn’t have to wait for the whole part to be finished to get access to new material.

Table of content

This chapter explains JPA relationships from a data access performance point of view.

11. Relationships
11.1 Relationship types     
11.2 @ManyToOne       
11.3 @OneToMany       
11.3.1 Bidirectional @OneToMany   
11.3.2 Unidirectional @OneToMany  
11.3.3 Ordered unidirectional @OneToMany
11.3.3.1 @ElementCollection    
11.4 @OneToOne      
11.4.1 Unidirectional @OneToOne   
11.4.2 Bidirectional @OneToOne  
11.5 @ManyToMany      
11.5.1 Unidirectional @ManyToMany 
11.5.2 Bidirectional @ManyToMany  
11.5.3 The @OneToMany alternative

Continue reading “High-Performance Java Persistence – Chapter 11 – Relationships”

Hibernate aggressive connection release

Hibernate connection providers

Hibernate needs to operate both in Java EE and stand-alone environments, and the database connectivity configuration can be done either declaratively or programmatically.

To accommodate JDBC Driver connections as well as RESOURCE_LOCAL and JTA DataSource configurations, Hibernate defines its own connection factory abstraction, represented by the org.hibernate.engine.jdbc.connections.spi.ConnectionProvider interface.

public interface ConnectionProvider 
    extends Service, Wrapped {

    public Connection getConnection() 
        throws SQLException;

    public void closeConnection(Connection connection) 
        throws SQLException;
    
    public boolean supportsAggressiveRelease();
}

Continue reading “Hibernate aggressive connection release”