Hibernate Physical Naming Strategy
Introduction In this article, I’m going to show you how the Hibernate Physical Naming Strategy works and how you can use it to customize the default mapping between entity attributes and database identifiers.
How to map SQL Server JSON columns using JPA and Hibernate
Introduction In this article, we are going to see how easy it is to map an SQL Server JSON column when using the Hypersistence Utils project. The Hypersistence Utils project supports JSON column types for PostgreSQL and MySQL and Oracle, and, as you will see in this article, the JsonType works just fine with Microsoft SQL Server.
How to map multiple JPA entities to one database table with Hibernate
Introduction In this article, we are going to see how we can map multiple JPA entities to one table with Hibernate. Using multiple entities can speed up both read and write operations. This question has been a recurring theme on StackOverflow, so I decided to explain the advantages of mapping multiple JPA entities to the same database table.
The best way to map an entity version property with JPA and Hibernate
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.
How to map camelCase properties to snake_case column names with Hibernate
Introduction In this article, you are going to learn how to map cameCase entity properties (e.g., phoneNumber) to snake_case column names (e.g., phone_number) using a Hibernate naming strategy. While you could achieve the same goal with the name attribute of JPA @Column annotation, it’s much more convenient to use a custom Hibernate strategy to apply this naming convention consistently.
How to fix the Hibernate “No Dialect mapping for JDBC type” issue
Introduction Recently, stumbled on this question on the Hibernate forum, and since I’ve been seeing it before on StackOverflow and bumped into it myself while working with JPA and Hibernate, I decided to turn the answer into an article. Therefore, in this article, you are going to find out how you can fix the “No Dialect mapping for JDBC type” Hibernate issue.
How to map a JPA entity to a View or SQL query using Hibernate
Introduction In this article, you are going to learn how to map a JPA entity to the ResultSet of a SQL query using the @Subselect Hibernate-specific annotation.
How to emulate @CreatedBy and @LastModifiedBy from Spring Data using the @GeneratorType Hibernate annotation
Introduction Hibernate comes with many additions to the standard JPA specification. One such example is the @GeneratorType annotation which allows you to customize the way a given entity property value is automatically generated. If you’re using Spring Data, you can simply use the @CreatedBy and @LastModifiedBy annotations and the annotated entity properties are going to be populated with the currently logged user. If you’re not using Spring Data, then you can easily emulate the same behavior using the Hibernate-specific @GeneratorType annotation and the ValueGenerator callback mechanism.
The best way to map a @NaturalId business key with JPA and Hibernate
Introduction In this article, you are going to learn what the Hibernate natural id is and how you can use it to fetch entities based on a business key. As I explained in this free chapter of my book, Hibernate offers many benefits over standard JPA. One such example is the @NaturalId mapping. In this article, you are going to see what is the best way to map a natural business key when using Hibernate.
The best way to map an Enum Type with JPA and Hibernate
Introduction Recently, I got a very good question on Twitter, and I decided that the best way to answer it is with a new article. In this article, we are going to see how various ways to map an Enum using JPA and Hibernate.