What's new in Hibernate ORM 5?
Asked Answered
E

2

53

I just saw that the 4th candidate got released for Hibernate 5. What's new in 5 compared to earlier versions?

Excisable answered 12/8, 2015 at 12:25 Comment(3)
You can find info about changes of new version by googling 'hibernte 5 changelog'. Here it is: github.com/hibernate/hibernate-orm/blob/master/changelog.txtRom
They removed autocommit unless you specify it, and they didn't document the change. Prepare to be screwed hard if you depended on that feature.Namtar
The lists are already long, but I think entity/unrelated joins is a very interesting and noteworthy feature that was introduced in 5.1.Heat
T
46

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.

Trollope answered 12/8, 2015 at 21:26 Comment(1)
but the SessionFacotry still not really serializable! i hope that this should be done in the next versionDrumbeat
C
46

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.
Clone answered 16/2, 2016 at 8:22 Comment(2)
Another incompatible change is about the sequence generators, Hibernate 5 defaults to the new enhanced generators and also use the pooled optimizer that is incompatible with previous strategy.Wiese
Yes I was just mentioning this was an important change in Hibernate 5. However instead of disabling the new generator mapping (which log a deprecation warning) I suggest to change the optimizer.Wiese

© 2022 - 2024 — McMap. All rights reserved.