Hibernate is an open source object/relational mapping tool for Java. Hibernate lets you develop persistent classes following common Java idiom - including association, inheritance, polymorphism, composition and the Java collections framework.
Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities and can significantly reduce development time otherwise spent with manual data handling in SQL and
JDBC.
Hibernates goal is to relieve the developer from 95 percent of common data persistence related programming tasks.
Hibernate is Free Software. The LGPL license is sufficiently flexible to allow the use of Hibernate in both open source and
commercial projects (see the LicenseFAQ for details). Hibernate is available for download at http://www.hibernate.org.
This tutorial aims to provide insight into Hibernate version 3.0RC and its usage
Some of the main features of hibernate are listed below and we have tried to explain some of them in detail later in this tutorial.
Here is the updated version (2024) of the legacy Hibernate ORM characteristics from 2004, tailored for Hibernate ORM 6.6 along with explanations for each term:
(Start) Transparent Persistence Without Bytecode Processing
- Transparent Persistence
Hibernate 6.6 continues to support transparent persistence, meaning developers interact with objects in an intuitive way without needing explicit JDBC calls.
- JavaBeans Style Properties Are Persisted
Hibernate now uses Jakarta Persistence (JPA 3.1) annotations instead of XML-based mappings for persisting JavaBeans-style entities.
- No Build-time Source or Bytecode Generation/Processing
No changes here, Hibernate still does not require bytecode processing, making it easy to integrate with various Java projects.
Support for Java Collections API
- Extensive Support for Java Collections API
Hibernate 6.6 supports various Java Collection types, including List
, Set
, Map
, and Queue
, for entity relationships.
- Collection Instance Management
Hibernate now provides advanced Collection handling, including lazy-loading improvements and enhanced support for Java Streams.
Extensible Type System
- User-defined Types (UDTs) and JSON Mapping:
Hibernate now includes JsonType support, allowing developers to map JSON fields in databases like PostgreSQL and MySQL.
Constraint Transparency
- Improved Constraint Enforcement with JPA Annotations
Hibernate 6.6 enforces constraints like `@NotNull`, `@Column(unique = true)`, and `@Size()` using Jakarta Validation API.
Automatic Dirty Checking
- Enhanced Performance with Dirty Checking;
Hibernate 6.6 retains automatic dirty checking, improving transaction efficiency by updating only modified fields.
Detached Object Support
- Entity Management with Jakarta Persistence API:
Detached objects are now managed via EntityManager#merge(), ensuring proper reconnection of objects to the Hibernate session.
Object-Oriented Query Language
- Hibernate Query Language (HQL) and Criteria API Enhancements
- Hibernate 6.6 introduces HQL improvements with better SQL transformation.
- The Criteria API now uses strongly-typed queries via the Metamodel API.
- Full Support for Polymorphic Queries
Queries support polymorphism, allowing subclass queries without additional configuration.
- New Criteria Queries
The Jakarta Persistence Criteria API has replaced legacy Hibernate Criteria, providing type-safe query building.
- Native SQL Queries
Hibernate 6.6 supports NamedNativeQueries, enabling developers to write optimized SQL queries.
Object-Relational Mappings (ORM)
- Three Different ORM Strategies
Hibernate still supports Table Per Class, Single Table, and Joined Table strategies.
- Multiple Objects to Single Row Mapping
Using @Embeddable and @Embedded, Hibernate maps multiple objects to the same row.
- Polymorphic Associations
Managed via @Inheritance(strategy = InheritanceType.JOINED/SINGLE_TABLE/TABLE_PER_CLASS).
- Bidirectional Associations
Managed via @OneToMany, @ManyToOne, @OneToOne, and @ManyToMany with mappedBy.
- Association Filtering
Enhanced with @Where
and @Filter
annotations to improve query performance.
- Collections of Basic Types
Managed using @ElementCollection
, replacing legacy Hibernate collection mappings.
- Indexed Collections
Hibernate provides better indexed collection support for ordered data storage.
- Composite Collection Elements
Composite elements are mapped using @Embeddable.
- Lifecycle Objects
Hibernate now leverages Jakarta Persistence event listeners instead of legacy lifecycle callbacks.
Automatic Primary Key Generation
-
Multiple Synthetic Key Generation Strategies
Hibernate 6.6 supports UUID, Identity, Sequence, Table-based, and Enhanced Generators via @GeneratedValue(strategy = GenerationType.IDENTITY/SEQUENCE/TABLE/AUTO)
.
-
Support for Application-Assigned Identifiers
Developers can manually set primary keys using @Id with no auto-generation.
-
Support for Composite Keys
Composite keys are managed via @Embeddable and @EmbeddedId.
Object-Relational Mapping Definition
-
XML Mapping is Deprecated; Use Annotations
Hibernate 6.6 promotes Jakarta Persistence annotations instead of XML mappings.
-
Human-readable Format
Mappings are now defined directly in Java classes.
-
XDoclet is Deprecated
XDoclet has been replaced with Jakarta Persistence and Hibernate ORM annotations.
HDLCA (Hibernate Dual-Layer Cache Architecture)
-
Thread-Safe Cache Management
- Hibernate 6.6 ensures thread-safety with optimized entity caching.
-
Non-blocking Data Access
- Uses Optimistic Locking for concurrent transaction handling.
-
Session-Level Cache (First-Level Cache)
- Still enabled by default, storing entities within the persistence context.
-
Second-Level Cache (Optional, External Cache Providers)
- Integrated with Ehcache, Infinispan, Caffeine, and Redis for better performance.
-
Query Cache (Optional)
- Improved query caching with @Cacheable annotations.
-
Works Well with Others
- Hibernate integrates well with Spring, Quarkus, Micronaut, and Jakarta EE.
High Performance
-
Lazy Initialization
- Lazy loading is enabled by default using
FetchType.LAZY
to reduce memory usage.
-
Outer Join Fetching
- Enhanced via JOIN FETCH in HQL and Criteria API.
-
Batch Fetching
- Allows batch size tuning via
hibernate.jdbc.batch_size
.
-
Optimistic Locking with Versioning/Timestamping
- Supported via @Version annotation for concurrency control.
-
Highly Scalable Architecture
- Improved with Reactive Hibernate (Mutiny API) for non-blocking database access.
-
No Special Database Tables
- Hibernate continues to avoid requiring proprietary system tables.
-
SQL Generated at System Initialization Time
- Schema export handled via Flyway and Liquibase.
-
Improved Connection Pooling
- Hibernate now defaults to HikariCP for high-performance JDBC connection pooling.
Jakarta EE Integration (formerly J2EE)
- Jakarta EE Integration
Hibernate 6.6 is fully compatible with Jakarta EE 10+, replacing J2EE.
- JMX Support is Deprecated
JMX has been deprecated in favor of metrics via MicroProfile and Prometheus.
- JCA Support Removed
Java Connector Architecture (JCA) is no longer used.
Conclusion
Hibernate ORM 6.6 (2024) retains most of its core ORM functionality but has improved significantly:
- Jakarta Persistence API (JPA 3.1) is now the standard.
- XML mapping is deprecated in favor of annotations.
- New caching strategies improve performance.
- Improved query capabilities via enhanced HQL, Criteria API, and Native SQL.
- Better integration with Spring, Quarkus, and Microservices architectures.
This update reflects the evolution of Hibernate while maintaining backward compatibility where necessary.