Hibernate ORM enables developers to more easily write applications whose data outlives the application process. As an Object/Relational Mapping (ORM) framework, Hibernate is concerned with data persistence as it applies to relational databases (via JDBC).
Hibernate solves object-relational impedance mismatch problems by replacing direct persistence-related database accesses with high-level object handling functions. Hibernate’s primary feature is mapping from Java classes to database tables (and from Java data types to SQL data types). Hibernate also provides data query and retrieval facilities. It generates SQL calls and relieves the developer from manual result set handling and object conversion. Applications using Hibernate are portable to supported SQL databases with little performance overhead.
In addition to its own “native” API, Hibernate is also an implementation of the Java Persistence API (JPA) specification. As such, it can be easily used in any environment supporting JPA including Java SE applications, Java EE application servers, Enterprise OSGi containers, etc.
Hibernate supports lazy initialization, numerous fetching strategies and optimistic locking with automatic versioning and time stamping. Hibernate requires no special database tables or fields and generates much of the SQL at system initialization time instead of at runtime. Hibernate consistently offers superior performance over straight JDBC code, both in terms of developer productivity and runtime performance.
Hibernate was designed to work in an application server cluster and deliver a highly scalable architecture. Hibernate scales well in any environment: Use it to drive your in-house Intranet that serves hundreds of users or for mission-critical applications that serve hundreds of thousands. Hibernate is well known for its excellent stability and quality, proven by the acceptance and use by tens of thousands of Java developers.
Mapping Java classes to database tables is accomplished through the configuration of an XML file or by using Java Annotations.
Read below java tutorials for understanding various concepts involved into hibernate.
Related Tags
Tutorials
EntityManager find() loads an entity with a SELECT or returns null, while getReference() returns a proxy without SQL. See when each runs SQL, when EntityNotFoundException and LazyInitializationException are thrown, and how to set a foreign key without loading the entity.
Map a natural id such as a license plate with Hibernate’s @NaturalId, load entities with em.find(…, KeyType.NATURAL), handle mutable and composite natural ids, and cache lookups with @NaturalIdCache, with the SQL and statement counts from Hibernate 7.4.
Hibernate throws “No row with the given identifier exists” when a proxy or an eager load asks for an id that has no row. See the real Hibernate 7.4 exceptions for getReference(), lazy and eager associations and concurrent deletes, and fix them with find(), orphan cleanup, a foreign key constraint or @NotFound.
Configure Ehcache 3 for Hibernate 7 with ehcache.xml: one cache per region, templates, ttl/tti expiry, heap and offheap sizing, missing_cache_strategy, concurrency strategies and per-region statistics, all verified by a runnable project.
Hibernate stops at startup with “Errors in named queries” when a JPQL named query uses a table name, a column name, SQL syntax or a broken parameter. See how to read NamedQueryValidationException in Hibernate 7 and fix each cause.
A Hibernate named query is a JPQL or SQL query declared once and run by name. Learn @NamedQuery, @NamedNativeQuery, orm.xml, parameters, result types, the startup check and JPA 3.2 typed references.
The Hibernate second level cache shares entity data across all sessions of an EntityManagerFactory. Learn the lookup order, what the cache stores, the concurrency strategies, collection and query caching, statistics and eviction with Hibernate 7.4 and Ehcache 3.
The Hibernate first level cache is the persistence context of one EntityManager. See with counted SQL on Hibernate 7.4 when find() and queries hit the database, how detach(), evict(), clear() and refresh() work, and how to keep long transactions small.
To insert an object with Hibernate, we pass a new entity to persist() inside a transaction. Learn when the INSERT runs for IDENTITY, SEQUENCE and assigned ids, how merge() and HQL insert statements work, and what replaced Session.save() in Hibernate 7.
A Hibernate one-to-many mapping links one parent entity to many children through a foreign key. Learn the bidirectional mappedBy form, the two unidirectional forms, the SQL each runs and the N+1 fix.
Map a many-to-many association in Hibernate 7 with @ManyToMany, @JoinTable and mappedBy, see the real SQL for Set and List, and add extra columns with a join entity.
Map a one-to-one association in Hibernate 7 with JPA @OneToOne: a foreign key with @JoinColumn, a bidirectional mapping with mappedBy, a shared primary key with @MapsId and a join table, with the SQL Hibernate runs.
Build your first Hibernate application with Hibernate 7.4, Java 25 and H2: the Maven dependencies, an entity, the configuration, and save, read, update and delete with the SQL each call runs.