jpa

How to assert Hibernate SQL statement count in tests

The data-access layer is often where performance problems emerge and what defines your application response time. Uncontrolled SQL queries can produce long-running transactions that affect the scalability of your software. Hibernate is a powerful tool, but it’s often criticized because it can sometimes have unpredictable behavior when it converts all your entities fetch/update to SQL statements (N+1 Select, Cartesian product…). How to track Hibernate SQL statements The easiest way to track the SQL statements is by enabling their logging, unfortunately, even if it’s useful in development, that cannot prevent regression of your data access queries in production, we need some testing to help us.

Spring Cache and JPA Cache differences

A cache is a good way of optimizing slow calls. The two common caches used in most Spring applications are Spring Cache and the JPA Cache. There are already a lot of very good articles on how to configure each one, but I want to emphasize on their differences. These caches are independent and configured differently, but they are both compatible with JCache (JSR-107) specification and can use the same cache implementation as EhCache.