Hibernate
Map Java objects to SQL tables with JPA and Hibernate, minus the surprises.
Take this course in the learning hubLessons
- Why ORM existsUnderstand the object/table mismatch and what Hibernate actually buys you.
- JPA vs HibernateKnow which annotations come from the spec and which ones are Hibernate-only extras.
- Entities and primary keysMap a class to a table and pick an id strategy that will not hurt you later.
- The persistence contextSee how the EntityManager tracks entities and moves them through their lifecycle.
- Dirty checking and flushingLearn why one setter updates a row, and when the SQL is actually sent.
- Transactions with @TransactionalUse Spring transactions properly and avoid the two mistakes that silently disable them.
- Mapping relationshipsMap @ManyToOne, @OneToMany and @ManyToMany, and know which side owns the foreign key.
- Lazy vs eager fetchingControl when Hibernate goes back to the database to load an association.
- The N+1 select problemSpot the query storm hiding behind a simple loop, and fix it three different ways.
- Cascading and orphan removalLet operations flow from parent to child without deleting rows you meant to keep.
- JPQL and the Criteria APIQuery by entity and field names, then build the same query dynamically when you must.
- Native SQL when you need itDrop to real SQL for what JPQL cannot express, without losing entity mapping.
- First and second level cacheTell the two Hibernate caches apart and know when the shared one earns its keep.
- Optimistic locking with @VersionStop concurrent updates from silently overwriting each other, without holding row locks.
- Schema generation vs migrationsUse Hibernate DDL for throwaway dev schemas and a migration tool for everything real.
- Spring Data JPA repositoriesGet CRUD and derived queries without writing an implementation, and know where the line is.
- Pagination and sortingPage through a large table without asking the database to count rows it will discard.
- Embeddables and element collectionsModel things with no identity of their own without inventing an entity, an id and a join.
- Mapping an inheritance hierarchyPick between one shared table, a table per class and a joined hierarchy with eyes open.
- Enums, dates and AttributeConverterStore enums and custom types in a form that survives the next refactor of your code.
- equals and hashCode for entitiesKeep an entity usable in a HashSet both before and after Hibernate assigns its id.
- Lifecycle callbacks and auditingStamp created and updated columns automatically, and know exactly when each hook runs.
- Batch inserts and bulk updatesTurn fifty round trips into one, and know what a bulk statement does to the context.
- Pessimistic locking and isolationTake a real database lock when retrying is not good enough, and pay the cost knowingly.
- Seeing the SQL Hibernate runsMake the generated SQL and the query count visible to you before your users find them.
- Testing the persistence layerWrite JPA tests that fail for the same reasons production would, not for H2 reasons.
- Why GenerationType.IDENTITY disables batch insertsThe id strategy quietly decides whether Hibernate can batch at all.
- Seeing the SQL Hibernate actually runsshow-sql is not enough - bind parameters, statement counts and the N+1 you cannot see.
- JOIN FETCH, entity graphs and the pagination trapFour ways to fetch an association, and when each one breaks.
- The second-level cache and when it hurtsCache regions, concurrency strategies, and the query cache people should usually avoid.
- equals, hashCode and detached entitiesThe default implementations break the moment an entity is persisted or detached.
- Bulk updates and the stale persistence contextA bulk UPDATE bypasses everything the ORM knows, including entities already loaded.