Recently, on 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.
Continue reading “The best way to do batch processing with JPA and Hibernate”
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
@OneToOne associations use an EAGER loading strategy by default. However, EAGER fetching is bad for performance so it’s better to use the
FetchType.LAZY fetching strategy for all association types.
In this article, we are going to see how the proxy mechanism works and how you can unproxy a given Proxy to the actual entity.
Continue reading “How does a JPA Proxy work and how to unproxy it with Hibernate”
PostgreSQL, like many modern RDBMS, offers both MVCC (Multi-Version Concurrency Control) and explicit pesimistic 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.
Continue reading “How do PostgreSQL advisory locks work”
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 (e.g. FlexyPool) or data access frameworks (e.g. Hibernate).
Unlike a typical RDBMS, CockroachDB is designed to be globally distributed and strongly resilient to disasters, hence its very unusual name. But what’s really exciting about CockroachDB is its non-locking timestamp ordering concurrency control mechanism which allows CockroachDB to run in Serializable isolation level, even if the database is massively distributed. Intriguing, right?
Continue reading “How to get started with CockroachDB”
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.
Continue reading “Why you should use the Hibernate ResultTransformer to customize result set mappings”