Diagnose and fix Hibernate ORM / Jakarta Persistence problems in plain Java: N+1 queries, lazy loading errors, identifier generation, entity equals/hashCode, cascades, pagination, batching, locking, caching, Lombok on entities, and Hibernate 6/7 differences. Use when reviewing or writing JPA entities, mappings, and queries. Framework-neutral.
Capabilities
Schema management rule
Review focus
Check statement counts for N+1, explicit LAZY on to-one associations, sequence-based ids with matching…
Getting started
Full instructionsInstall the skill, then ask your AI tool for the task in plain words. The full SKILL.md below shows what it covers.
Instructions: SKILL.mdv1.0.0
Hibernate ORM and Jakarta Persistence
Problem -> anti-pattern -> fix library for entity mapping and querying. Framework-neutral: it covers EntityManager/Session behavior, JPQL/HQL, and mapping annotations. If the project uses Spring Boot and the java-springboot and spring-boot-testing skills are installed, use them for Spring Data repositories, transaction wiring, and @DataJpaTest; for Panache and reactive persistence see the Quarkus skills. Integration tests against a real database: java-testcontainers.
First: detect the stack
- Read
pom.xml/build.gradle(or the dependency tree) forhibernate-coreand the persistence API:jakarta.persistence(Hibernate 6+/Jakarta EE 9+) vsjavax.persistence(Hibernate 5, seejavax-to-jakarta-migration). - Note the Hibernate major version; behavior differs (see
references/tooling-and-versions.md). Hibernate 6.0-6.1 implement Jakarta Persistence 3.0, 6.2+ implement 3.1, 7.x implements 3.2, and Hibernate 7 needs Java 17+. - Note the database and whether the schema is managed by Flyway/Liquibase.
- Turn on SQL logging and statistics in a test (see
references/tooling-and-versions.md) before "optimizing" anything: measure statement counts.
Quick decision table
| Symptom | Likely cause | Go to |
|---|---|---|
| Many similar SELECTs for one request | N+1 on lazy association | references/fetching-and-n-plus-one.md |
LazyInitializationException |
Lazy access outside session | references/fetching-and-n-plus-one.md |
HHH000104 / HHH90003004 warning, big memory use |
Pagination with collection fetch join | references/queries-pagination-batching.md |
| Inserts slow, no JDBC batching | IDENTITY ids or batching not configured |
references/identifiers-and-entity-design.md, references/queries-pagination-batching.md |
Duplicate rows / lost children / Set anomalies |
Bad equals/hashCode or cascade misuse |
references/identifiers-and-entity-design.md, references/associations-and-cascade.md |
| Lost updates, deadlocks | Missing locking strategy | references/locking-transactions-caching.md |
| Stale or surprising data with caches | Second-level/query cache misuse | references/locking-transactions-caching.md |
Schema drift, ddl-auto in prod |
No migration tool | references/tooling-and-versions.md |
Top rules (apply during review)
- Associations:
@ManyToOne/@OneToOnedefault to EAGER; declarefetch = FetchType.LAZYexplicitly.@OneToMany/@ManyToManyare LAZY by default and should stay so. Choose fetching per query (JOIN FETCH, entity graph), not by making mappings EAGER. - Prefer
@ManyToOneowning side plus a bidirectional@OneToMany(mappedBy=...)only when needed; keep both sides in sync through helper methods. SetorListfor collections? UseSetfor@ManyToMany; a unidirectional@OneToManywith@JoinColumnorListwithout an order has costly update patterns.- Never use
CascadeType.REMOVE/ALLon@ManyToOneor@ManyToMany. UseorphanRemovalonly on a true parent-owned child collection. - Ids:
SEQUENCE(pooled optimizer,allocationSizematching the DB increment) for generated numeric ids;IDENTITYdisables JDBC insert batching; use UUIDs (time-ordered preferred) when ids must be generated client-side. - Entities: no Lombok
@Data/@EqualsAndHashCode/@ToStringover associations; implementequals/hashCodedeliberately. - Return DTOs/projections from read endpoints rather than entities; never expose entities (lazy proxies) directly in an API.
- Paginate with a stable
ORDER BYincluding a unique tiebreaker; never combinesetMaxResultswith a collectionJOIN FETCH. - Keep transactions short, at the service boundary; no remote calls or user interaction inside one.
- Write and flush in batches for bulk work and clear the persistence context periodically.
- Verify behavior with statement counts in tests against the real database engine.
- Follow the schema management rule below.
Schema management rule
This is the single rule other skills refer to by name:
- Prototype/local:
hibernate.hbm2ddl.auto=update(orcreate-dropfor throwaway tests) is acceptable. - Production (default): versioned migrations with Flyway or Liquibase, and
hibernate.hbm2ddl.auto=validate(ornone). Add them when the user wants versioned migrations or the app is headed to production. - Externally managed schema:
none(orvalidate); do not add a migration tool.
Review focus
Check statement counts for N+1, explicit LAZY on to-one associations, sequence-based ids with matching allocationSize, and equals/hashCode stable across transient to persistent. Version-dependent details (Hibernate 5/6/7): references/tooling-and-versions.md.
References
references/fetching-and-n-plus-one.md: N+1 detection and fixes, lazy vs eager,LazyInitializationException, open-session-in-view, DTO projections.references/identifiers-and-entity-design.md: id generation,equals/hashCode, Lombok, records vs entities, enums and converters, value types.references/associations-and-cascade.md: bidirectional helpers, cascade,orphanRemoval, collection choice,@ManyToMany.references/queries-pagination-batching.md: pagination (offset, keyset, in-memory warning), bulk operations, JDBC batching,StatelessSession.references/locking-transactions-caching.md: optimistic/pessimistic locking, transaction boundaries, flush modes, second-level cache.references/tooling-and-versions.md: SQL logging, statistics, tests, connection pool sizing, migrations, Hibernate 5/6/7 differences.
Canonical docs: Hibernate ORM user guide https://docs.hibernate.org/orm/current/userguide/html_single/ and Jakarta Persistence https://jakarta.ee/specifications/persistence/. Deep background articles: https://vladmihalcea.com/.
Upgrading (fetch the page for the target version; prefer it over this skill): migration guides https://hibernate.org/orm/documentation/migrate/ (6.6: https://docs.hibernate.org/orm/6.6/migration-guide/, 7.0: https://docs.hibernate.org/orm/7.0/migration-guide/), release notes https://hibernate.org/orm/releases/.
Explore more skills
Browse all- Generate ImageGenerate images using AI. Use when asked to generate, create, or make images, textures, icons, sprites, artwork, visual…
- Anti UI SlopStop coding agents from shipping generic UI. Use UIZZE's 800,000+ real web and iOS screens to build product-specific…
- Security ReviewAI-powered codebase security scanner that reasons about code like a security researcher — tracing data flows,…
- Dotnet Best PracticesEnsure .NET/C# code meets best practices for the solution/project.
- Convert PDF to MdConverts PDF (.pdf) documents into Markdown so their contents can be accurately analyzed, summarized, searched, or…
- Meeting MinutesGenerate concise, actionable meeting minutes for internal meetings. Includes metadata, attendees, agenda, decisions,…
Security
Signing
SignedSLSA L2- Signed by
- skills-hub.ai distributor
- Method
- Distributor-signed by skills-hub.aiSigned with the skills-hub.ai Ed25519 distributor key over this exact slug, version and content. Check it with `npx @skills-hub-ai/cli verify`.
- Key
- skills-hub-ed25519-2026-11
- Signed
Reviews (0)
More from GitHub Copilot
View source →You might also like
- GuideGitHub Copilot Browser Tools Are GA: AI Agents Now Verify Their Own Front-End WorkAs of July 1, 2026, GitHub Copilot's browser tools hit general availability in VS Code — letting AI coding agents drive a real browser to verify their own front-end changes. Here's what changed, how it works, and how to apply the same pattern in Claude Code and Cursor.7 min read
- GuideKimi K2.7 Code in GitHub Copilot: The First Open-Weight Model in a Mainstream AI Coding AssistantMoonshot AI's Kimi K2.7 Code landed in GitHub Copilot on July 1 — the first open-weight model in the five-lab model picker. MIT-licensed weights on Hugging Face, hosted on Azure, billed at GPT-5.4 mini tier pricing. Here's what it means for your workflow.7 min read
- GuideGitHub Copilot AI Credits: First-Week Reality Check (June 2026)On June 1, GitHub Copilot dropped flat-rate billing and switched to token-based AI Credits. One week in: some developers report bills jumping from $29 to $750/month. Here's the math, who gets hit hardest, and how to stay in budget.8 min read
Frequently asked questions about java-hibernate-jpa
What does the java-hibernate-jpa skill do?
Diagnose and fix Hibernate ORM / Jakarta Persistence problems in plain Java: N+1 queries, lazy loading errors, identifier generation, entity equals/hashCode, cascades, pagination, batching, locking, caching, Lombok on entities, and Hibernate 6/7 differences. Use when reviewing or writing JPA entities, mappings, and queries. Framework-neutral. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the java-hibernate-jpa skill?
Run `npx @skills-hub-ai/cli install github-copilot-java-hibernate-jpa` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/github-copilot-java-hibernate-jpa/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does java-hibernate-jpa work with?
java-hibernate-jpa runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the java-hibernate-jpa skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use java-hibernate-jpa after installing it?
In Claude Code, type `/github-copilot-java-hibernate-jpa` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the java-hibernate-jpa skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.
Badge for your README
Show that this skill is on Skills Hub. The badge links back to this page and shows the live install count.
[](https://skills-hub.ai/skills/github-copilot-java-hibernate-jpa)<a href="https://skills-hub.ai/skills/github-copilot-java-hibernate-jpa"><img src="https://skills-hub.ai/api/badges/skill/github-copilot-java-hibernate-jpa" alt="Install on Skills Hub"></a>More options in the badge docs.