Loading...

Follow Vlad Mihalcea's Blog | Teaching is my way of l.. on Feedspot

Continue with Google
Continue with Facebook
or

Valid

Introduction In this article, we are going to see what is the best way to set up the query timeout interval with JPA and Hibernate. Setting the query timeout allows you to cancel slow-running queries that would, otherwise, put pressure on database resources. The “javax.persistence.query.timeout” JPA query hint As I explained in this article, the Java Persistence API defines the notion of query hint, which unlike what its name might suggest, it has nothing to do with database query hints. The JPA query hint is a Java Persistence provider customization option. JPA... Read More

The post Query timeout with JPA and Hibernate appeared first on Vlad Mihalcea.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Introduction In this article, we are going to test the MySQL 8 implementation of custom SQL CHECK constraints. Although the CHECK clause is a standard SQL feature, prior to MySQL 8.0.16, the clause was parsed and ignored, so this functionality could only be emulated via BEFORE INSERT and UPDATE triggers. Custom SQL CHECK constraints As I explained in this article, custom SQL CHECK constraints are very useful to ensure non-nullability constraints for JPA entity subclass-specific attributes when using the SINGLE TABLE JPA inheritance strategy. To understand the problem, consider we have the... Read More

The post MySQL 8 support for custom SQL CHECK constraints appeared first on Vlad Mihalcea.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Introduction In this article, we are going to see what JPA query hints are, and get to know all the query hints supported by Hibernate. Understanding the Hibernate query hints is very important when developing a non-trivial enterprise application since they allow you to customize the way queries are executed by Hibernate. JPA query hints The Java Persistence API defines the notion of query hint, which unlike what its name might suggest, it has nothing to do with database query hints. The JPA query hint is a Java Persistence provider customization option.... Read More

The post A beginner’s guide to JPA and Hibernate query hints appeared first on Vlad Mihalcea.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 
5r
Vlad Mihalcea's Blog | Teaching is m.. by Vladmihalcea - 3w ago

The post 5r appeared first on Vlad Mihalcea.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Introduction In this article, we are going to see what is the best way to map the entity version property with JPA and Hibernate. Most often, we overlook the basic entity type mappings, focusing more on associations or querying options. However, basic types can also have a significant impact on application performance, especially if the type in question is used in many entity mappings. Version property and optimistic locking As I previously explained, the entity version property is used by the Hibernate optimistic locking mechanism to prevent lost updates. However, a typical... Read More

The post The best way to map an entity version property with JPA and Hibernate appeared first on Vlad Mihalcea.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Introduction In this article, we are going to see how optimistic locking version property works when using JPA and Hibernate. Most often, we overlook basic concepts and focus only on more advanced topics such as associations or queries, without realizing that basic mappings can also have a significant impact when it comes to persistence effectiveness and efficiency. Lost updates anomaly Relational database systems have emerged in the time of mainframe systems when the client was interacting with the database from a terminal using a dedicated connection. Back then, when the client needed... Read More

The post Optimistic locking version property with JPA and Hibernate appeared first on Vlad Mihalcea.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Introduction In this article, we are going to see how we can tune the performance of the Spring Petclinic application using Hypersistence Optimizer. Now, while you can manually analyze your data access layer to make sure that JPA and Hibernate are properly configured, it’s much better if you can automate this task. That’s because new entities might be mapped in the future, and you want to make sure that the same performance-specific rules are consistently applied on every commit. Hypersistence Optimizer allows you to automatically detect JPA and Hibernate issues during development,... Read More

The post Tuning Spring Petclinic JPA and Hibernate configuration with Hypersistence Optimizer appeared first on Vlad Mihalcea.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Introduction A very useful, yet lesser-known, Hibernate feature is the ability to intercept and modify any auto-generated SQL statement using the Hibernate StatementInspector utility. In this article, we are going to see how the Hibernate StatementInspector mechanism works. StatementInspector The Hibernate StatementInspector is a functional interface that looks as follows: The inspect method takes an SQL statement that’s about to be executed by Hibernate and allows you to modify the SQL statement and return it to the Hibernate StatementPreparer. To register an implementation of the StatementInspector interface with Hibernate, you can use... Read More

The post How to intercept and modify SQL queries with the Hibernate StatementInspector appeared first on Vlad Mihalcea.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Introduction Recently, I noticed the hibernate.query.fail_on_pagination_over_collection_fetch configuration property that was introduced in Hibernate 5.2, and I had absolutely no idea it can be used to prevent the HHH000104 Hibernate issues. As previously explained, if you want to overcome the HHH000104: firstResult/maxResults specified with collection fetch; applying in memory! issue, you have to either use 2 queries or a window function to fetch and limit the number of parent records while making sure you always fetch all their associated child entities. Even if the HHH000104 issue is logged as a warning message, it... Read More

The post How to detect HHH000104 issues with hibernate.query.fail_on_pagination_over_collection_fetch appeared first on Vlad Mihalcea.

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Introduction As already explained, Hibernate provides a very flexible statistics mechanism. The Hibernate metrics can be accessed either programmatically via the org.hibernate.stat.Statistics interface or via JMX (Java Management Extensions). In this article, you are going to see how you can expose the Hibernate statistics metrics using JMX. Configuration By default, the Hibernate statistics mechanism is not enabled, so you need to activate it using the following configuration property: To expose the Hibernate metrics via JMX, you also need to set the hibernate.jmx.enabled configuration property: Now, Hibernate is going to collect metrics and... Read More

The post How to expose Hibernate Statistics via JMX appeared first on Vlad Mihalcea.

Read Full Article

Read for later

Articles marked as Favorite are saved for later viewing.
close
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview