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.
A beginner’s guide to natural and surrogate database keys
Types of primary keys All database tables must have one primary key column. The primary key uniquely identifies a row within a table therefore it’s bound by the following constraints: UNIQUE NOT NULL IMMUTABLE When choosing a primary key we must take into consideration the following aspects: the primary key may be used for joining other tables through a foreign key relationship the primary key usually has an associated default index, so the more compact the data type the less space the index will take the primary key assignment must ensure uniqueness… Read More