Three years of blogging

Woohoo!

It’s been three years since I started this blog, and every year I happen to write a report. If you are curious, check out the previous reports:

Page Views

meta_36m_wp_months

In these three years, I got over 1.200.000 page views and the last month was the first one to break the 70.000 views threshold.

Continue reading “Three years of blogging”

How to customize the JDBC batch size for each Persistence Context with Hibernate

Introduction

JDBC batching has a significant impact on reducing transaction response time. As previously explained, you can enable batching for INSERT, UPDATE and DELETE statements with just one configuration property:

<property name="hibernate.jdbc.batch_size" value="5"/>

However, this setting affects every Persistence Context, therefore every business use case inherits the same JDBC batch size. Although the hibernate.jdbc.batch_size configuration property is extremely useful, it would be great if we could customize the JDBC batch size on a per Persistence Context basis. This article demonstrates how easily you can accomplish this task.

Continue reading “How to customize the JDBC batch size for each Persistence Context with Hibernate”

How to implement a custom basic type using Hibernate UserType

Introduction

StackOverflow is a gold mine! Check out this question I bumped into this morning. Basically, our Hibernate user wants a resilient CharacterType which works with NULL or empty values. To make it even more interesting, we are going to make it work even if the underlying database column contains more than one character.

Continue reading “How to implement a custom basic type using Hibernate UserType”

The best way to lazy load entity attributes using JPA and Hibernate

Introduction

When fetching an entity, all attributes are going to be loaded as well. This is because every entity attribute is implicitly marked with the @Basic annotation whose default fetch policy is FetchType.EAGER.

However, the attribute fetch strategy can be set to FetchType.LAZY, in which case the entity attribute is loaded with a secondary select statement upon being accessed for the first time.

@Basic(fetch = FetchType.LAZY)

This configuration alone is not sufficient because Hibernate requires bytecode instrumentation to intercept the attribute access request and issue the secondary select statement on demand.

Continue reading “The best way to lazy load entity attributes using JPA and Hibernate”