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

- 142,745
- 71
- 566
- 911

- 1,529
- 2
- 12
- 16
-
2You can find info about changes of new version by googling 'hibernte 5 changelog'. Here it is: https://github.com/hibernate/hibernate-orm/blob/master/changelog.txt – Mohsen Sep 20 '15 at 12:08
-
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. – Alkanshel Sep 02 '16 at 00:50
-
1The lists are already long, but I think entity/unrelated joins is a very interesting and noteworthy feature that was introduced in 5.1. – Christian Beikov Jan 20 '17 at 08:47
2 Answers
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.

- 6,982
- 16
- 51
- 59

- 8,406
- 10
- 50
- 67
-
but the SessionFacotry still not really serializable! i hope that this should be done in the next version – Nassim MOUALEK Aug 25 '15 at 20:24
There's a long list of things that have been changed in Hibernate 5:
A new bootstrap API so we can bootstrap a JPA environment programmatically without the need of a
persistence.xml
file.Starting in 5.0 Hibernate Spatial is part of the Hibernate project so we can handle GIS data too.
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
andjava.time.ZonedDateTime
- DATE:
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.
Hibernate's native APIs (
Session
, etc) have been updated to use generic types. No need to cast when fetching entities.Hibernate 5.0 extends this to a broader set of types (e.g.
UUID
).Second-level cache by reference. This feature enables direct storage of entity references into the second level cache for immutable entities.
Starting with Hibernate 5.0, we have a completely new User Guide that was written from scratch.
Hibernate 5.1 adds the following features:
Hibernate 5.2 adds support for:
- Java 1.8, so you can now use
Query.stream()
- The Hibernate
Session
extendsEntityManager
so you can get access to all JPA methods right from aSession
- Support for JCache
- Session-level batch size
- Global timezone setting (e.g. UTC) for
Timestamp
andTime
- Distinct pass-through hint
- More efficient JPQL and HQL parsing of constant values
- The
hibernate.connection.provider_disables_autocommit
resource-local transaction optimization. - Better handling of Criteria API literals.

- 142,745
- 71
- 566
- 911
-
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. – bric3 Feb 16 '17 at 16:13
-
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. – bric3 Feb 16 '17 at 16:46