How to inherit properties from a base class entity using @MappedSuperclass with JPA and Hibernate

Introduction

Last week, one of my blog readers asked me of a way to reuse the @Id mapping so that it won’t have to be declared on each an every entity.

Because this is a good opportunity to introduce @MappedSuperclass, I decided to answer the question with a blog post.

Continue reading “How to inherit properties from a base class entity using @MappedSuperclass with JPA and Hibernate”

Why should not use the AUTO JPA GenerationType with MySQL and Hibernate

Introduction

As I already mentioned, you should never use the TABLE identifier generator since it does not scale properly. In this post, I’ll show you why you should not rely on the AUTO GenerationType strategy if you’re Hibernate application uses MySQL.

Continue reading “Why should not use the AUTO JPA GenerationType with MySQL and Hibernate”

How to replace the TABLE identifier generator with either SEQUENCE or IDENTITY in a portable way

Introduction

As previously explained, the TABLE identifier generator does not scale, so you should avoid id. However, some enterprise applications might need to run on both MySQL (which does not support database sequences), as well as Oracle, PostgreSQL, and SQL Server 2012.

This is article is going to explain how easily you can achieve this goal using the JPA mapping overriding.

Continue reading “How to replace the TABLE identifier generator with either SEQUENCE or IDENTITY in a portable way”

How to combine the Hibernate assigned generator with a sequence or an identity column

Introduction

The entity identifier can either be manually assigned, or it can be automatically generated by an identity column or a database sequence.

In this post, I’ll show you how you can mix the assigned generator with an identity column or a database sequence.

Continue reading “How to combine the Hibernate assigned generator with a sequence or an identity column”