In this special Java Daily edition we will learn more about Vlad Mihalcea and what he thinks about important Java related topics.
Vlad Mihalcea is a Java Champion. He wrote the High-Performance Java Persistence book which became one of the best-selling Java books on Amazon. He is currently working as a Hibernate Developer Advocate, and in his free time he develops various open-source projects (e.g. Hibernate-Types and FlexyPool) and answers questions on StackOverflow.
Java Daily: Will Hibernate remain the persistence provider of choice in the future? Which is the ideal type of project where is mostly applicable?
Vlad:
The Hibernate ORM project has a very significant market share. For example, the 2018 Snyk technology report shows that more than 54% of Java projects use Hibernate.
So, Hibernate is going to remain the persistence provider of choice in the future for the following reasons:
– It is open source and supports a wide range of relational database systems.
– It is actively maintained.
– It has great documentation and community support.
– There are plenty of books available, like the High-Performance Java Persistence best-seller.
– You can find up-to-date video courses that can teach you how to get the most out of JPA and Hibernate.
Hibernate is designed for OLTP applications, and that’s where it’s mostly applicable. This is because Hibernate is very convenient for writing data as it provides automatic batching, lost update prevention or the dirty checking mechanism.
Java Daily: Which cache provider would you recommend using in conjunction with Hibernate and why? Is this cache “cluster-ready” ?
Vlad: Traditionally, Ehcache is the most common second-level cache provider used with Hibernate, and to run it in a cluster environment you can use Terracotta.
Another alternative is to use Infinispan which is a distributed in-memory key/value store that is developed by Red Hat.
Java Daily: Do you think in the future Hibernate will support the upcoming “reactive programming” trend?
Vlad: Reactive programming and ACID transactions don’t mix well. While there are JDBC Drivers offering a “reactive” JDBC Driver, in reality, they simply use a Thread Pool to submit work and return the control immediately to the caller.
Both Oracle and Pivotal work on providing a reactive alternative to JDBC.
However, any framework that was built on top of JDBC will not automatically work with
a reactive driver, so new frameworks will have to emerge to support reactive database programming.
Java Daily: Have you come across examples of splitting the Read and Write model with Hibernate (Hibernate and CQRS). Can this speed up the performance?
Vlad: Splitting reads and writes has been done ever since database replication was invented.
You can issue read-write transactions on the Primary node and read-only transactions on the
Follower nodes.
CQRS is a niche technology that is applicable to very specific systems where it is appropriate
to accept any incoming message without validating it prior to recording it into the log.
Unlike a CQRS system, a relational database validates any modification prior to writing it to the
transaction log, so no inconsistency can happen.
So, for the vast majority of applications, OLTP databases are still the de-facto approach.
In fact, even Google needs an OLTP database. Even if they had BigTable long before Hadoop,
they created Spanner as they needed a globally distributed OLTP database system.
Without Spanner, implementing Google AdWords and Play would be much more difficult.
All in all, relational and NewSQL database systems are going to lead the database market for many years to come.
Java Daily: In a constantly growing project, how would you ensure that Hibernate performance is not compromised over time?
Vlad: Knowledge is the answer. The only way to make sure you are using Hibernate properly is to learn how to use it.
Luckily, there many good resources to learn Hibernate. The official User Guide is a very good place to start.
And, if you want to truly master JPA and Hibernate, then you should definitely read
my High-Performance Java Persistence book.
Java Daily: Which Hibernate features are overlooked the most?
Vlad: The fact that Hibernate can run native SQL queries is the most overlooked feature.
Many developers assume that they should never ever run any native SQL query if they use Hibernate. But that’s a very wrong approach to using any JPA implementation.
While JPQL and Criteria API are fine for fetching data that’s about to be modified, for read-only projections, reports or analytics, there is no better tool than SQL.
For more details about this topic, check out my ‘createNativeQuery’ is a Magic Wand article.
Do you have more questions for Vlad Mihalcea? Do you think you may have something to add? Feel free to leave a comment below. Let’s give back to the Java community together!