bauer-king-hibernate

Applies JPA and Hibernate mapping, fetching, and transaction guidance from the Bauer-King-Gregory book.

Updated Jul 28, 2026
One-click install
npx skills add https://github.com/zademy/book-to-skill-zademy --skill bauer-king-hibernate-zademy
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: bauer-king-hibernate
Source: https://github.com/zademy/book-to-skill-zademy/tree/main/.agents/skills/bauer-king-hibernate
Command: npx skills add https://github.com/zademy/book-to-skill-zademy --skill bauer-king-hibernate-zademy

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Designing JPA/Hibernate persistence layers involves many subtle decisions — entity vs. value type mapping, inheritance strategies, fetch plans, locking, and caching — where wrong defaults cause n+1 queries, broken equality semantics, and scalability failures. This Skill provides the distilled frameworks, patterns, and anti-patterns from "Java Persistence with Hibernate, 2nd Edition" so those decisions follow the authors' proven guidance. ## Core Features & Use Cases - Chapter-level knowledge base: 20 chapter files covering ORM fundamentals, mapping strategies, transactions, fetching, queries, and application architecture, each with core ideas, worked CaveatEmptor examples, pitfalls, and when-to-apply guidance. - Patterns and anti-patterns catalog: 14 recurring patterns (surrogate keys, lazy-by-default fetching, optimistic locking, deliberate scaling) plus a table of named anti-patterns with fixes. - Cheatsheet and glossary: Quick reference for annotations, configuration properties, EntityManager/locking/caching APIs, query snippets, and author-specific terminology. - Use Case: When mapping a bidirectional Item–Bid association, consult the patterns file to decide between a mapped collection with mappedBy and orphanRemoval versus a simple query, avoiding the shared-reference trap. ## Quick Start Ask the AI to help design or review a JPA entity mapping, fetch plan, or transaction strategy, and it will load the relevant chapter, pattern, or cheatsheet guidance from this Skill.

Frequently Asked Questions about bauer-king-hibernate

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose between SINGLE_TABLE and JOINED inheritance in JPA?▼

Choose SINGLE_TABLE when subclasses declare few properties and differ mainly in behavior, accepting nullable subclass columns. Choose JOINED when subclasses carry many distinct non-null properties, since it keeps the schema normalized but adds join cost to polymorphic queries.

How do I fix the n+1 selects problem in Hibernate?▼

Fix n+1 selects by keeping mappings lazy and fetching eagerly per use case with join fetch in JPQL, entity graphs, or fetch profiles. Global mitigations include @BatchSize for batched proxy initialization and subselect fetching for collections.

Should I use FetchType.EAGER on JPA associations?▼

No. The authors advise mapping everything lazy because FetchType.EAGER is a global promise you cannot revoke per query. Fetch eagerly per use case instead with join fetch, entity graphs, or fetch profiles.

What should equals and hashCode be based on for JPA entities?▼

Base equals() and hashCode() on a business key such as a username, never on the generated ID (which is null before persist) and never on default object identity. This keeps Sets consistent when mixing detached and freshly loaded instances.

When should I use optimistic versus pessimistic locking in Hibernate?▼

Use optimistic locking by default: put @Version on every mutable entity and handle OptimisticLockException at the boundary. Reserve PESSIMISTIC_WRITE database locks for hot rows within short transactions, since database locks serialize access.

When is the second-level cache worth enabling in Hibernate?▼

Enable it selectively with ENABLE_SELECTIVE and @Cacheable only for reference data that rarely changes, using READ_ONLY or NONSTRICT_READ_WRITE strategies. Verify hit ratios with the Statistics API, and skip the query result cache unless measurements justify it.