A high-performance data access layer requires a lot of knowledge about database internals, JDBC, JPA, Hibernate, and this post summarizes some of the most important techniques you can use to optimize your enterprise application.
1. SQL statement logging
If you’re using a framework that generates statements on your behalf, you should always validate each statement effectiveness and efficiency. A testing-time assertion mechanism is even better because you can catch N+1 query problems even before you commit your code.
2. Connection management
Database connections are expensive, therefore you should always use a connection pooling mechanism.
Because the number of connections is given by the capabilities of the underlying database cluster, you need to release connections as fast as possible.
In performance tuning, you always have to measure, and setting the right pool size is no different. A tool like FlexyPool can help you find the right size even after you deployed your application into production.
Continue reading “14 High-Performance Java Persistence Tips”
Since not all relational database systems support JSON types, Hibernate does not come with a built-in JSON
Type mapper. Traditionally, all custom types have been supplied via a
UserType implementation. However, a
UserType is not very developer friendly so, in this post, I’m going to show how you can do a better job using
Continue reading “How to map JSON objects using generic Hibernate Types”
Another milestone has been reached
The second part of High-Performance Java Persistence book is out. It’s been almost a year since I started writing this book, and seven months since I published the first part.
Continue reading “High-Performance Java Persistence – Part Two”
One of my blog readers bumped into the assigned generator with a sequence or an identity column post and wondered if it was possible to generate String-based identifiers instead.
I accepted the challenge and answered his question on StackOverflow. However, this post is going to explain this topic in greater detail, so there we go.
Continue reading “How to implement a custom String-based sequence identifier generator with Hibernate”
As previously explained, using the JPA entity business key for
hashCode is always best choice. However, not all entities feature a unique business key, so we need to use another database column that is also unique, like the primary key.
But using the entity identifier for equality is very challenging, and this post is going to show you how you can use it without issues.
Continue reading “How to implement equals and hashCode using the JPA entity identifier (Primary Key)”