Vlad Mihalcea

How to enable bytecode enhancement dirty checking in Hibernate

Are you struggling with performance issues in your Spring, Jakarta EE, or Java EE application?

Imagine having a tool that could automatically detect performance issues in your JPA and Hibernate data access layer long before pushing a problematic change into production!

With the widespread adoption of AI agents generating code in a heartbeat, having such a tool that can watch your back and prevent performance issues during development, long before they affect production systems, can save your company a lot of money and make you a hero!

Hypersistence Optimizer is that tool, and it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, Micronaut, or Play Framework.

So, rather than allowing performance issues to annoy your customers, you are better off preventing those issues using Hypersistence Optimizer and enjoying spending your time on the things that you love!

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.

Read More

High-Performance Java Persistence – Chapter 12 – Inheritance

Are you struggling with performance issues in your Spring, Jakarta EE, or Java EE application?

Imagine having a tool that could automatically detect performance issues in your JPA and Hibernate data access layer long before pushing a problematic change into production!

With the widespread adoption of AI agents generating code in a heartbeat, having such a tool that can watch your back and prevent performance issues during development, long before they affect production systems, can save your company a lot of money and make you a hero!

Hypersistence Optimizer is that tool, and it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, Micronaut, or Play Framework.

So, rather than allowing performance issues to annoy your customers, you are better off preventing those issues using Hypersistence Optimizer and enjoying spending your time on the things that you love!

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 

Read More

How do JPA and Hibernate define the AUTO flush mode

Are you struggling with performance issues in your Spring, Jakarta EE, or Java EE application?

Imagine having a tool that could automatically detect performance issues in your JPA and Hibernate data access layer long before pushing a problematic change into production!

With the widespread adoption of AI agents generating code in a heartbeat, having such a tool that can watch your back and prevent performance issues during development, long before they affect production systems, can save your company a lot of money and make you a hero!

Hypersistence Optimizer is that tool, and it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, Micronaut, or Play Framework.

So, rather than allowing performance issues to annoy your customers, you are better off preventing those issues using Hypersistence Optimizer and enjoying spending your time on the things that you love!

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.

Read More

High-Performance Java Persistence – Chapter 11 – Relationships

Are you struggling with performance issues in your Spring, Jakarta EE, or Java EE application?

Imagine having a tool that could automatically detect performance issues in your JPA and Hibernate data access layer long before pushing a problematic change into production!

With the widespread adoption of AI agents generating code in a heartbeat, having such a tool that can watch your back and prevent performance issues during development, long before they affect production systems, can save your company a lot of money and make you a hero!

Hypersistence Optimizer is that tool, and it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, Micronaut, or Play Framework.

So, rather than allowing performance issues to annoy your customers, you are better off preventing those issues using Hypersistence Optimizer and enjoying spending your time on the things that you love!

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

Read More

How does aggressive connection release work in Hibernate

Are you struggling with performance issues in your Spring, Jakarta EE, or Java EE application?

Imagine having a tool that could automatically detect performance issues in your JPA and Hibernate data access layer long before pushing a problematic change into production!

With the widespread adoption of AI agents generating code in a heartbeat, having such a tool that can watch your back and prevent performance issues during development, long before they affect production systems, can save your company a lot of money and make you a hero!

Hypersistence Optimizer is that tool, and it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, Micronaut, or Play Framework.

So, rather than allowing performance issues to annoy your customers, you are better off preventing those issues using Hypersistence Optimizer and enjoying spending your time on the things that you love!

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();
}

Read More

High-Performance Java Persistence – Chapter 10 – Mapping Types and Identifiers

Are you struggling with performance issues in your Spring, Jakarta EE, or Java EE application?

Imagine having a tool that could automatically detect performance issues in your JPA and Hibernate data access layer long before pushing a problematic change into production!

With the widespread adoption of AI agents generating code in a heartbeat, having such a tool that can watch your back and prevent performance issues during development, long before they affect production systems, can save your company a lot of money and make you a hero!

Hypersistence Optimizer is that tool, and it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, Micronaut, or Play Framework.

So, rather than allowing performance issues to annoy your customers, you are better off preventing those issues using Hypersistence Optimizer and enjoying spending your time on the things that you love!

Part 2, Chapter 10

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 the core mapping elements used by Hibernate and details the basic type and the identifier generators.

10. Mapping Types and Identifiers 
10.1 Types
10.1.1 Primitive types
10.1.2 String types 
10.1.3 Date and Time types
10.1.4 Numeric types
10.1.5 Binary types 
10.1.6 UUID types 
10.1.7 Other types
10.1.8 Custom types 
10.2 Identifiers
10.2.1 UUID identifiers 
10.2.1.1 The assigned generator 
10.2.2 The legacy UUID generator
10.2.2.1 The newer UUID generator 
10.2.3 Numerical identifiers
10.2.3.1 Identity generator 
10.2.3.2 Sequence generator 
10.2.3.3 Table generator
10.2.3.4 Optimizers 
10.2.3.4.1 The hi/lo algorithm
10.2.3.4.2 The default sequence identifier generator
10.2.3.4.3 The default table identifier generator 
10.2.3.4.4 The pooled optimizer 
10.2.3.4.5 The pooled-lo optimizer
10.2.3.5 Optimizer gain 
10.2.3.5.1 Sequence generator performance gain
10.2.3.5.2 Table generator performance gain 
10.2.3.6 Identifier generator performance 

Read More

I just joined the Hibernate team at RedHat

Are you struggling with performance issues in your Spring, Jakarta EE, or Java EE application?

Imagine having a tool that could automatically detect performance issues in your JPA and Hibernate data access layer long before pushing a problematic change into production!

With the widespread adoption of AI agents generating code in a heartbeat, having such a tool that can watch your back and prevent performance issues during development, long before they affect production systems, can save your company a lot of money and make you a hero!

Hypersistence Optimizer is that tool, and it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, Micronaut, or Play Framework.

So, rather than allowing performance issues to annoy your customers, you are better off preventing those issues using Hypersistence Optimizer and enjoying spending your time on the things that you love!

Hibernate Developer Advocate

Today is my first day working as a Developer Advocate for the Hibernate ORM project at RedHat. My job consists in helping the community getting the most out of Hibernate. This is really exciting since I can continue the work that I started when I came out with this blog.

If we take the 2015 Java Ecosystem Report issued by Dzone, Hibernate has a 63.9% market share. There are millions of Java developers depending on a relatively small team for delivering their favorite JPA implementation. So, this job carries lot of responsibility when you think about it.

Giving answers

You’ll find me on the Hibernate forum or Stack Overflow, trying to get the best answer for your questions.

Improving documentation

Documentation is extremely important to every open source project, and we want to align it with the latest development achievements (the 4.x and 5.x branches).
Improving the Hibernate documentation is really a full-time project but, when thinking of how much impact it has on the community, it’s worth all the effort.

Fixing issues

I look forward to helping my team addressing any reported issue in a timely fashion. Hibernate is a very complex framework and providing backward compatibility for so many features is really a tough job. Any extra help is always welcome.

Conferences

From now on, you’ll probably see me at Java conferences, where I plan on talking about Hibernate, data access best practices and high-performance Java persistence.

All in all, there is a lot of work to do, and I am looking forward to helping our Hibernate community.

Transactions and Concurrency Control eBook

How to bootstrap Hibernate without the persistence.xml file

Are you struggling with performance issues in your Spring, Jakarta EE, or Java EE application?

Imagine having a tool that could automatically detect performance issues in your JPA and Hibernate data access layer long before pushing a problematic change into production!

With the widespread adoption of AI agents generating code in a heartbeat, having such a tool that can watch your back and prevent performance issues during development, long before they affect production systems, can save your company a lot of money and make you a hero!

Hypersistence Optimizer is that tool, and it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, Micronaut, or Play Framework.

So, rather than allowing performance issues to annoy your customers, you are better off preventing those issues using Hypersistence Optimizer and enjoying spending your time on the things that you love!

Why?

JPA relies heavily on the persistence.xml configuration file, and the standard API to bootstrap a JPA provider programmatically requires too much boilerplate code. While in a typical enterprise application, providing a persistence.xml file is not really an issue, this requirement doesn’t get along with unit testing, especially when tests are completely isolated and they need to validate different aspects of JPA or Hibernate.

That was an issue that I bumped into when writing test cases for the High-Performance Java Persistence book. All my tests need to be isolated, and not all of them share the same settings or entities.

In my case, using a single persistence.xml file was definitely out of the question because any change would have a rippling effect throughout the whole test suite.

Read More

High-Performance Java Persistence – Chapter 9 – Hibernate Connection Management

Are you struggling with performance issues in your Spring, Jakarta EE, or Java EE application?

Imagine having a tool that could automatically detect performance issues in your JPA and Hibernate data access layer long before pushing a problematic change into production!

With the widespread adoption of AI agents generating code in a heartbeat, having such a tool that can watch your back and prevent performance issues during development, long before they affect production systems, can save your company a lot of money and make you a hero!

Hypersistence Optimizer is that tool, and it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, Micronaut, or Play Framework.

So, rather than allowing performance issues to annoy your customers, you are better off preventing those issues using Hypersistence Optimizer and enjoying spending your time on the things that you love!

Part 2, Chapter 9

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 how to handle connections in Hibernate and how to monitor their usage as well as the statement that gets automatically generated, and the table of contents looks like this:

9. Connection Management and Monitoring
9.1 JPA connection management
9.2 Hibernate connection providers 
9.2.1 DriverManagerConnectionProvider
9.2.2 C3P0ConnectionProvider 
9.2.3 HikariConnectionProvider 
9.2.4 DatasourceConnectionProvider 
9.2.5 Connection release modes 
9.3 Monitoring connections 
9.3.1 Hibernate statistics 
9.3.1.1 Customizing statistics 
9.4 Statement logging
9.4.1 Statement formatting 
9.4.2 Statement-level comments 
9.4.3 Logging parameters 
9.4.3.1 DataSource-proxy 
9.4.3.2 P6Spy

Read More

High-Performance Java Persistence – Chapter 8 – Why JPA and Hibernate matter

Are you struggling with performance issues in your Spring, Jakarta EE, or Java EE application?

Imagine having a tool that could automatically detect performance issues in your JPA and Hibernate data access layer long before pushing a problematic change into production!

With the widespread adoption of AI agents generating code in a heartbeat, having such a tool that can watch your back and prevent performance issues during development, long before they affect production systems, can save your company a lot of money and make you a hero!

Hypersistence Optimizer is that tool, and it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, Micronaut, or Play Framework.

So, rather than allowing performance issues to annoy your customers, you are better off preventing those issues using Hypersistence Optimizer and enjoying spending your time on the things that you love!

Second part, Chapter 8

Now that the first part of my book is published, it’s time to focus on the second part, which covers both JPA and Hibernate.
From now on, every new chapter is going to be released right after it’s completed, so the reader doesn’t have to wait for the whole part to be finished to get access to new chapters.

Table of content

This chapter aims to remind the reader why Hibernate has its place in high-performance data access, and the table of contents looks like this:

8. Why JPA and Hibernate matter
8.1 The impedance mismatch
8.2 JPA vs Hibernate
8.3 Schema ownership
8.4 Write-based optimizations
8.5 Read-based optimizations
8.6 Wrap-up

Read More