Best way to map the JPA and Hibernate ManyToMany relationship

Introduction In this article, I’m going to show you the best way to map a ManyToMany association when using JPA and Hibernate. As simple as JPA annotations might be, it’s not always obvious how efficient they are behind the scenes.

How to install DB2 Express-C on Docker and set up the JDBC connection properties

Introduction While developing Hibernate, I need to test the code base against a plethora of relational database systems: Oracle, SQL Server, PostgreSQL, MySQL, MariaDB, Informix, and of course DB2. However, having all these databases installed on my system is far from ideal, so I rely a lot on Docker for this task. In this article, I’m going to show how easily you can install DB2 on Docker and set up the JDBC connection so that you can run Hibernate tests on DB2.

The best way to do batch processing with JPA and Hibernate

Introduction Recently, one of my followers asked me to answer a question on Quora about batch processing, and, since the question was really interesting, I decided to turn it into a blog post. In this article, you are going to find out what batch processing is, why do we use it, and how to use it properly with JPA and Hibernate.

How does a JPA Proxy work and how to unproxy it with Hibernate

Introduction In this article, I’m going to explain how JPA and Hibernate Proxy objects work, and how you can unproxy an entity Proxy to get access to the underlying POJO instance. The JPA lazy loading mechanism can either be implemented using Proxies or Bytecode Enhancement so that calls to lazy associations can be intercepted and relationships initialized prior to returning the result back to the caller. Initially, in JPA 1.0, it was assumed that Proxies should not be a mandatory requirement, and that’s why @ManyToOne and @OneToOne associations use an EAGER loading… Read More

How do PostgreSQL advisory locks work

Introduction PostgreSQL, like many modern RDBMS, offers both MVCC (Multi-Version Concurrency Control) and explicit pessimistic locking for various use cases when you want a custom concurrency control mechanism. However, PostgreSQL also offers advisory locks which are very convenient to implement application-level concurrency control patterns. In this article, we are going to explain how PostgreSQL advisory locks work and how you should use them.

How to get started with CockroachDB

Introduction CockroachDB is a really interesting database system, getting the best of both RDBMS and NoSQL. It’s been developed by former Google developers, and it’s inspired by Google Spanner. However, unlike Google Spanner, which is offered as a service in Google Cloud, CockroachDB is an open-source database that can be installed on premise. Also, CockroackDB allows you to use the PostgreSQL drivers as opposed to Spanner which only supports the gRPC protocol. So, you can practically reuse all the frameworks that have emerged in the Java ecosystem like connection pools, monitoring proxies… Read More

2 best tools that can help you solve ANY software development problem

Introduction You read it correctly. Any is a very broad term. However, these two tools that I’m going to talk about in this article allow me to solve any software development problem across a very broad range of skills.

Why you should use the Hibernate ResultTransformer to customize result set mappings

Introduction JPA queries allow you to fetch either entities or DTO projections. However, sometimes you want a combined result set as illustrated in this Hibernate forum question.

The best way to map a @OneToMany relationship with JPA and Hibernate

Introduction While adding a @OneToMany relationship is very easy with JPA and Hibernate, knowing the right way to map such an association so that it generates very efficient SQL statements is definitely not a trivial thing to do. In a relational database system, a one-to-many association links two tables based on a Foreign Key column so that the child table record references the Primary Key of the parent table row. As straightforward as it might be in a relational database, when it comes to JPA, the one-to-many database association can be represented… Read More