What's new in Hibernate ORM 5?

Some exciting features has been added/enhanced in Hibernate 5.x. Have a quick look.

1. Hibernate Search

Hibernate Search transparently indexes your objects and offers fast regular, full-text and geolocation search. Ease of use and easy clustering are core.

  • Full-text search for entities - find by approximation (fuzzy search)
  • Cluster-friendly - offers several easy to setup clustering strategies
  • Faceting and geolocation - Geolocalized entities are as easy as @Spatial

For more details on Hibernate Search view this.

2. Hibernate Validator

Hibernate Validator comes with a handful of built-in validation rules like Email, Length, NotBlank etc.

Express validation rules in a standardized way using annotation-based constraints and benefit from transparent integration with a wide variety of frameworks.

For more details on Hibernate Validator view this.

3. Improved Java 8 Support

Java 8 date/time data types (JSR 310) are supported and can be validated via @Past and @Future. Also Optional and JavaFX types are supported via an improved ValidatedValueUnwrapper.

4. Hibernate OGM

Just released the first stable version.

5. Bootstrapping API

New bootstrapping API - better determinism, better integration


A few other things:

  • Scanning support for non-JPA usage
  • NamingStrategy has been removed in favor of a better designed API
  • Ability to handle additional Java types for id attributes marked as GenerationType#AUTO. Built-in support for Number and UUID. Expandable via new org.hibernate.boot.model.IdGeneratorStrategyInterpreter extension.
  • Additionally, support for AttributeConverters has been expanded and more fully realized

Check Hibernate ORM Roadmap for more details.


There's a long list of things that have been changed in Hibernate 5:

  1. A new bootstrap API so we can bootstrap a JPA environment programmatically without the need of a persistence.xml file.

  2. Starting in 5.0 Hibernate Spatial is part of the Hibernate project so we can handle GIS data too.

  3. The Java 8 Date and Time types are supported in domain model mappings. The mapping between the standard SQL Date/Time types and the supported Java 8 Date/Time class types looks as follows;

    • DATE: java.time.LocalDate
    • TIME: java.time.LocalTime, java.time.OffsetTime
    • TIMESTAMP: java.time.Instant, java.time.LocalDateTime, java.time.OffsetDateTime and java.time.ZonedDateTime
  4. The bytecode enhancement mechanism was redesigned from scratch, and Hibernate features both a Maven and a Gradle plugin. There are three main aspects which we can enhance with bytecode instrumentation:

    • Lazy initialization: Fields can be declared as LAZY and they will be fetched only when being accessed for the first time.

    • Dirty checking: Entities are enhanced so that they can keep track of all the properties that get changed after being loaded in a Persistence Context.

    • Bidirectional associations: It's possible to synchronize both sides of a bidirectional association automatically, even if the developer only updates a single side.

  5. Hibernate's native APIs (Session, etc) have been updated to use generic types. No need to cast when fetching entities.

  6. Hibernate 5.0 extends this to a broader set of types (e.g. UUID).

  7. Second-level cache by reference. This feature enables direct storage of entity references into the second level cache for immutable entities.

  8. Starting with Hibernate 5.0, we have a completely new User Guide that was written from scratch.

Hibernate 5.1 adds the following features:

  1. You can now join unrelated entities in JPQL and HQL queries
  2. Multi-entity load by identififer

Hibernate 5.2 adds support for:

  1. Java 1.8, so you can now use Query.stream()
  2. The Hibernate Session extends EntityManager so you can get access to all JPA methods right from a Session
  3. Support for JCache
  4. Session-level batch size
  5. Global timezone setting (e.g. UTC) for Timestamp and Time
  6. Distinct pass-through hint
  7. More efficient JPQL and HQL parsing of constant values
  8. The hibernate.connection.provider_disables_autocommit resource-local transaction optimization.
  9. Better handling of Criteria API literals.