Welcome to the Hibernate community newsletter in which we share blog posts, forum, and StackOverflow questions that are especially relevant to our users.


Since Hibernate 5, the GenerationType.AUTO identifier strategy is handled by the SequenceStyleGenerator. If the underlying database supports sequences, then a database sequence is going to be used to generate the entity identifier. Otherwise, the TABLE generator will be used, and this can cause performance and scalability issue, as illustrated by this article.

Therefore, if you’re using MySQL you are better off using the IDENTITY generator. If database portability is your concern, then you can use the SEQUENCE generator by default since it is supported by Oracle, SQL Server 2012, PostgreSQL and MariaDB 10.3, and just fall back to IDENTITY using the orm.xml for MySQL. For more details about how you can override an annotation-based mapping using XML configs, check out this article as well.

Anghel Leonard wrote an article where he covers over 50 JPA and Hibernate performance tips:

When working with Hibernate, it’s common to use the Camel Case (e.g. phoneNumber) notation for entity properties while, on the database side, the Snake Case (e.g. phone_number) notation is more widespread. Although you could use the @Column annotation to map each individual entity attribute to its database identifier, it’s much more convenient to use a Hibernate naming strategy that applies all these rules consistently.

This article introduces the CamelCaseToSnakeCaseNamingStrategy which is available via the hibernate-types open-source project.

In this article, Eugen Paraschiv shows you how to fix the java.lang.String cannot be cast to [Ljava.lang.String error when using JPA and Hibernate.

The JPA specification provides a dual meaning for the DISTINCT keyword in a JPQL or Criteria API query. While passing the DISTINCT keyword is fine for scalar queries, you don’t want to do that for entity queries where DISTINCT is only used after the JDBC ResultSet is assembled in a parent-child tree representation. To prevent passing the DISTINCT keyword to the SQL query, you should use the HINT_PASS_DISTINCT_THROUGH JPA query hint.

Hibernate 5.4 provides a way to build JPA EntityGraphs from a String representation. For more details about this new feature, check out this article.

Time to upgrade

Hibernate ORM 5.4.0 CR1 has been released. This is the first release of the 5.4 version, so we are looking forward to getting your feedback about the latest features we integrated into the framework. For more details, check out the release notes.

Hibernate Search 5.10.5 has been released. For more details, check out the release notes.

Back to top