본문으로 건너뛰기
cccskills
무료GitHub에 공개

java-hibernate-jpa

Review and fix Java database mappings and queries with Hibernate ORM and Jakarta Persistence. Diagnose excessive queries, delayed data loading errors, and update conflicts, then check entity design and database behavior using SQL measurements.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

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.

실행 점수 미검증

설치 방법 보기

이럴 때 유용합니다

  • Investigating excessive database queries
  • Fixing LazyInitializationException
  • Reviewing entity relationships and deletion behavior
  • Improving pagination and bulk inserts

포함된 파일(7)

  • SKILL.md6.5 KB
  • references/associations-and-cascade.md4.4 KB
  • references/fetching-and-n-plus-one.md5.8 KB
  • references/identifiers-and-entity-design.md7.1 KB
  • references/locking-transactions-caching.md5.7 KB
  • references/queries-pagination-batching.md6.8 KB
  • references/tooling-and-versions.md6.1 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

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

  1. Read pom.xml/build.gradle (or the dependency tree) for hibernate-core and the persistence API: jakarta.persistence (Hibernate 6+/Jakarta EE 9+) vs javax.persistence (Hibernate 5, see javax-to-jakarta-migration).
  2. 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+.
  3. Note the database and whether the schema is managed by Flyway/Liquibase.
  4. Turn on SQL logging and statistics in a test (see references/tooling-and-versions.md) before "optimizing" anything: measure statement counts.

Quick decision table

SymptomLikely causeGo to
Many similar SELECTs for one requestN+1 on lazy associationreferences/fetching-and-n-plus-one.md
LazyInitializationExceptionLazy access outside sessionreferences/fetching-and-n-plus-one.md
HHH000104 / HHH90003004 warning, big memory usePagination with collection fetch joinreferences/queries-pagination-batching.md
Inserts slow, no JDBC batchingIDENTITY ids or batching not configuredreferences/identifiers-and-entity-design.md, references/queries-pagination-batching.md
Duplicate rows / lost children / Set anomaliesBad equals/hashCode or cascade misusereferences/identifiers-and-entity-design.md, references/associations-and-cascade.md
Lost updates, deadlocksMissing locking strategyreferences/locking-transactions-caching.md
Stale or surprising data with cachesSecond-level/query cache misusereferences/locking-transactions-caching.md
Schema drift, ddl-auto in prodNo migration toolreferences/tooling-and-versions.md

Top rules (apply during review)

  1. Associations: @ManyToOne/@OneToOne default to EAGER; declare fetch = FetchType.LAZY explicitly. @OneToMany/@ManyToMany are LAZY by default and should stay so. Choose fetching per query (JOIN FETCH, entity graph), not by making mappings EAGER.
  2. Prefer @ManyToOne owning side plus a bidirectional @OneToMany(mappedBy=...) only when needed; keep both sides in sync through helper methods.
  3. Set or List for collections? Use Set for @ManyToMany; a unidirectional @OneToMany with @JoinColumn or List without an order has costly update patterns.
  4. Never use CascadeType.REMOVE/ALL on @ManyToOne or @ManyToMany. Use orphanRemoval only on a true parent-owned child collection.
  5. Ids: SEQUENCE (pooled optimizer, allocationSize matching the DB increment) for generated numeric ids; IDENTITY disables JDBC insert batching; use UUIDs (time-ordered preferred) when ids must be generated client-side.
  6. Entities: no Lombok @Data/@EqualsAndHashCode/@ToString over associations; implement equals/hashCode deliberately.
  7. Return DTOs/projections from read endpoints rather than entities; never expose entities (lazy proxies) directly in an API.
  8. Paginate with a stable ORDER BY including a unique tiebreaker; never combine setMaxResults with a collection JOIN FETCH.
  9. Keep transactions short, at the service boundary; no remote calls or user interaction inside one.
  10. Write and flush in batches for bulk work and clear the persistence context periodically.
  11. Verify behavior with statement counts in tests against the real database engine.
  12. 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 (or create-drop for throwaway tests) is acceptable.
  • Production (default): versioned migrations with Flyway or Liquibase, and hibernate.hbm2ddl.auto=validate (or none). Add them when the user wants versioned migrations or the app is headed to production.
  • Externally managed schema: none (or validate); 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/.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

acquire-codebase-knowledge

무료요약 있음

기존 프로젝트의 코드와 설정을 조사해 기술 구성, 구조, 아키텍처, 규칙, 연동, 테스트, 우려 사항을 다루는 문서 7개를 작성합니다. 근거 파일을 연결하고 미확인 항목을 표시하며, 계획과 실제 구현의 차이를 드러냅니다.

  • 익숙하지 않은 코드베이스 파악하기
  • 프로젝트 인수인계 문서 준비하기
  • 설계 문서와 실제 구현 비교하기
github/awesome-copilot4만2026년 10월 24일 업데이트

acreadiness-assess

무료요약 있음

AgentRC로 저장소의 AI 에이전트 활용 준비도를 평가하고 독립 실행형 HTML 보고서를 생성합니다. 9개 영역의 점수와 우선순위별 개선안을 확인하고, 조직에 맞춘 채점 정책도 적용할 수 있습니다.

  • AI 에이전트 도입 전 준비도 확인
  • 평가 결과에 따라 개선 우선순위 결정
  • 조직별 정책으로 점수 산정
github/awesome-copilot4만2026년 10월 24일 업데이트

프로젝트의 실제 코드에서 언어, 프레임워크, 개발 관례를 파악해 AI 코딩 에이전트용 지침 파일을 생성하거나 갱신합니다. 하나의 파일에 모으거나 주제와 프로젝트 영역별로 나누며, 쓰기 전에 변경 내용을 미리 볼 수 있습니다.

  • VS Code Copilot용 지침 만들기
  • 바뀐 개발 규칙을 지침에 반영
  • 모노레포 영역별 규칙 정리
github/awesome-copilot4만2026년 10월 24일 업데이트

acreadiness-policy

무료요약 있음

AgentRC 준비도 평가를 팀이나 조직의 기준에 맞게 조정합니다. JSON 정책에서 검사 중요도와 수준을 바꾸고, 불필요한 검사를 끄며, 통과율을 설정해 CI 자동 검사에도 적용할 수 있습니다.

  • 조직 공통 평가 기준 만들기
  • AI 관련 준비 상태만 평가
  • 검사 항목의 중요도 조정
github/awesome-copilot4만2026년 10월 24일 업데이트

ad-campaign-analyzer

무료요약 있음

제공한 광고 성과 데이터를 분석해 낭비되는 지출과 성과가 좋은 광고를 찾고, 중단·예산 증액·추가 테스트 후보를 정리합니다. 여러 플랫폼을 비교하고 A/B 테스트의 차이를 평가해 예산 재배분 방안도 제시합니다.

  • 중단할 광고나 키워드 찾기
  • 예산을 늘릴 캠페인과 대상 찾기
  • A/B 테스트 결과의 유의성 확인
github/awesome-copilot4만2026년 10월 24일 업데이트

add-educational-comments

무료요약 있음

지정한 코드 파일에 학습용 주석을 추가해 문법, 프로그래밍 개념, 설계 선택의 이유를 설명합니다. 독자의 지식에 맞춰 설명의 깊이와 반복 정도를 조절하며 파일 구조와 형식을 유지합니다.

  • 기존 코드에 초보자용 설명 추가
  • 문법이나 설계 방식을 선택한 이유 설명
  • 독자의 경험에 맞춰 주석 조정
github/awesome-copilot4만2026년 10월 24일 업데이트

github의 스킬 모두 보기

이 스킬의 문제 신고