The best way to test the data access layer
Introduction In this article, we are going to see what is the best way to test the data access layer when using a relational database system. First, we will talk about the pros and cons of unit testing. While unit testing is fine for validating independent logic units, when it comes to testing the data access layer, integration testing is more useful. Next, we will discuss about the difference between integration testing and system integration testing and see the benefits of using a data platform like Aiven. With Aiven, not only can… Read More
Hibernate StatelessSession Upsert
Introduction In this article, we are going to see how the Hibernate StatelessSession Upsert method works. As I explained in this article, the UPSERT operation allows you to INSERT a record if there is no such record matching the filtering criteria or to UPDATE it in case the record exists. While many relational database systems offer the standard MERGE command to execute the UPSERT command, the syntax may differ slightly from one database to the other. Therefore, it’s great that Hibernate provides a portable way to achieve this goal.
Index Selectivity
Introduction In this article, we are going to see how Index Selectivity works in relational database systems and why the database Optimizer might choose to avoid using an index if the number of matching records is large. Index selectivity is inversely proportional to the number of index entries matched by a given value. So, a unique index has the highest selectivity because only a single entry can be matched by any given value. On the other hand, if column values are skewed, then a column value matching a large number of table… Read More
How to batch INSERT statements with MySQL and Hibernate
Introduction In this article, we are going to see how we can batch INSERT statements when using MySQL and Hibernate. While Hibernate has long supported automated JDBC batch inserts, this feature doesn’t work when using the IDENTITY identifier generator strategy. Unfortunately, MySQL doesn’t support SEQUENCE objects, so using IDENTITY is the only reasonable option. Therefore, I’m going to show you a technique you can use to get Hibernate batch INSERT statements for entities that use the IDENTITY generator.
The best way to use Spring Data JPA Stream methods
Introduction In this article, we are going to see what is the best way to use Spring Data JPA Stream query methods. When having to fetch a larger result set, the advantage of using a Java Stream is that the query result set could be fetched progressively instead of getting all the data at once.