affaan-m/ECC

jpa-patterns

Spring Boot'ta entity tasarımı, ilişkiler, sorgu optimizasyonu, transaction'lar, auditing, indeksleme, sayfalama ve pooling için JPA/Hibernate kalıpları.

66Collecting
See how to use itView GitHub source
npx skills add https://github.com/affaan-m/ECC --skill "docs/tr/skills/jpa-patterns"
Automated source guideDocumentationDeep source

Source checked Jul 28, 2026·Refresh due Oct 26, 2026

Reorganized from the pinned upstream SKILL.md

Source-grounded documentation guide: jpa-patterns

Spring Boot'ta veri modelleme, repository'ler ve performans ayarlaması için kullanın.

npx skills add https://github.com/affaan-m/ECC --skill "docs/tr/skills/jpa-patterns"
Check the pinned source

The pinned source contains enough sections and task detail for a source-grounded deep guide; automated content is still not an independent test.

554 source words · 11 usable sections

Documentation workflow

Read jpa-patterns through these 5 source sections

Sections are extracted automatically from the pinned SKILL.md and link back to the source.

01

Ne Zaman Aktifleştirmeli

JPA entity'leri ve tablo eşlemelerini tasarlarken

SKILL.md · Ne Zaman Aktifleştirmeli
JPA entity'leri ve tablo eşlemelerini tasarlarkenİlişkileri tanımlarken (@OneToMany, @ManyToOne, @ManyToMany)Sorguları optimize ederken (N+1 önleme, fetch stratejileri, projections)
02

Entity Tasarımı

Review the “Entity Tasarımı” section in the pinned source before continuing.

SKILL.md · Entity Tasarımı
Review and apply the “Entity Tasarımı” source section.
03

İlişkiler ve N+1 Önleme

Varsayılan olarak lazy loading; gerektiğinde sorgularda JOIN FETCH kullan

SKILL.md · İlişkiler ve N+1 Önleme
Varsayılan olarak lazy loading; gerektiğinde sorgularda JOIN FETCH kullanKoleksiyonlarda EAGER kullanmaktan kaçın; okuma yolları için DTO projections kullan- Varsayılan olarak lazy loading; gerektiğinde sorgularda JOIN FETCH kullan - Koleksiyonlarda EAGER kullanmaktan kaçın; okuma yolları için DTO projections kullan
04

Repository Kalıpları

Hafif sorgular için projections kullan:

SKILL.md · Repository Kalıpları
Hafif sorgular için projections kullan:- Hafif sorgular için projections kullan:
05

Transaction'lar

Servis metodlarını @Transactional ile işaretle

SKILL.md · Transaction'lar
Servis metodlarını @Transactional ile işaretleOkuma yollarını optimize etmek için @Transactional(readOnly = true) kullanPropagation'ı dikkatle seç; uzun süreli transaction'lardan kaçın

SkillSignal prompt templates

Provide the task, context, and acceptance criteria

These prompts were written by SkillSignal from the source structure; they are not upstream text.

Source-grounded prompt

Use for a documentation task while explicitly checking the source sections.

Use jpa-patterns for this documentation task: [task]. Inputs and constraints: [details]. Work through these pinned SKILL.md sections: “Ne Zaman Aktifleştirmeli”, “Entity Tasarımı”, “İlişkiler ve N+1 Önleme”, “Repository Kalıpları”, “Transaction'lar”. Cite the concrete requirements that shape each step, do not invent capabilities absent from the source, and verify the result against: [acceptance criteria].

Documentation checklist

Verify each item before delivery

The source section “Ne Zaman Aktifleştirmeli” has been checked.

The source section “Entity Tasarımı” has been checked.

The source section “İlişkiler ve N+1 Önleme” has been checked.

The source section “Repository Kalıpları” has been checked.

Choose a different workflow

When another Skill is the better fit

FAQ

What does the jpa-patterns source document cover?

Spring Boot'ta veri modelleme, repository'ler ve performans ayarlaması için kullanın.

How do I install jpa-patterns?

The source record exposes this install command: npx skills add https://github.com/affaan-m/ECC --skill "docs/tr/skills/jpa-patterns". Inspect the command and pinned source before running it.

Repository stars
234,327
Repository forks
35,711
Quality
66/100
Source repository last pushed

Quality breakdown

Based on traceable docs and repository signals; stars are not treated as quality.

66/100
Documentation23/30
Specificity11/25
Maintenance20/20
Trust signals12/25
View original Skill.mdThis page is parsed directly from the repository SKILL.md without editorial rewriting. Collected: Jul 28, 2026 · about 2 min

JPA/Hibernate Kalıpları

Spring Boot'ta veri modelleme, repository'ler ve performans ayarlaması için kullanın.

Ne Zaman Aktifleştirmeli

  • JPA entity'leri ve tablo eşlemelerini tasarlarken
  • İlişkileri tanımlarken (@OneToMany, @ManyToOne, @ManyToMany)
  • Sorguları optimize ederken (N+1 önleme, fetch stratejileri, projections)
  • Transaction'ları, auditing'i veya soft delete'leri yapılandırırken
  • Sayfalama, sıralama veya özel repository metodları kurarken
  • Connection pooling (HikariCP) veya second-level caching ayarlarken

Entity Tasarımı

@Entity
@Table(name = "markets", indexes = {
  @Index(name = "idx_markets_slug", columnList = "slug", unique = true)
})
@EntityListeners(AuditingEntityListener.class)
public class MarketEntity {
  @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  @Column(nullable = false, length = 200)
  private String name;

  @Column(nullable = false, unique = true, length = 120)
  private String slug;

  @Enumerated(EnumType.STRING)
  private MarketStatus status = MarketStatus.ACTIVE;

  @CreatedDate private Instant createdAt;
  @LastModifiedDate private Instant updatedAt;
}

Auditing'i etkinleştir:

@Configuration
@EnableJpaAuditing
class JpaConfig {}

İlişkiler ve N+1 Önleme

@OneToMany(mappedBy = "market", cascade = CascadeType.ALL, orphanRemoval = true)
private List<PositionEntity> positions = new ArrayList<>();
  • Varsayılan olarak lazy loading; gerektiğinde sorgularda JOIN FETCH kullan
  • Koleksiyonlarda EAGER kullanmaktan kaçın; okuma yolları için DTO projections kullan
@Query("select m from MarketEntity m left join fetch m.positions where m.id = :id")
Optional<MarketEntity> findWithPositions(@Param("id") Long id);

Repository Kalıpları

public interface MarketRepository extends JpaRepository<MarketEntity, Long> {
  Optional<MarketEntity> findBySlug(String slug);

  @Query("select m from MarketEntity m where m.status = :status")
  Page<MarketEntity> findByStatus(@Param("status") MarketStatus status, Pageable pageable);
}
  • Hafif sorgular için projections kullan:
public interface MarketSummary {
  Long getId();
  String getName();
  MarketStatus getStatus();
}
Page<MarketSummary> findAllBy(Pageable pageable);

Transaction'lar

  • Servis metodlarını @Transactional ile işaretle
  • Okuma yollarını optimize etmek için @Transactional(readOnly = true) kullan
  • Propagation'ı dikkatle seç; uzun süreli transaction'lardan kaçın
@Transactional
public Market updateStatus(Long id, MarketStatus status) {
  MarketEntity entity = repo.findById(id)
      .orElseThrow(() -> new EntityNotFoundException("Market"));
  entity.setStatus(status);
  return Market.from(entity);
}

Sayfalama

PageRequest page = PageRequest.of(pageNumber, pageSize, Sort.by("createdAt").descending());
Page<MarketEntity> markets = repo.findByStatus(MarketStatus.ACTIVE, page);

Cursor benzeri sayfalama için, sıralama ile birlikte JPQL'de id > :lastId ekle.

İndeksleme ve Performans

  • Yaygın filtreler için indeksler ekle (status, slug, foreign key'ler)
  • Sorgu kalıplarına uyan composite indeksler kullan (status, created_at)
  • select * kullanmaktan kaçın; sadece gerekli sütunları project et
  • saveAll ve hibernate.jdbc.batch_size ile yazmaları batch'le

Connection Pooling (HikariCP)

Önerilen özellikler:

spring.datasource.hikari.maximum-pool-size=20
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.validation-timeout=5000

PostgreSQL LOB işleme için ekle:

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

Caching

  • 1st-level cache EntityManager başına; transaction'lar arası entity'leri tutmaktan kaçın
  • Okuma ağırlıklı entity'ler için second-level cache'i dikkatle düşün; eviction stratejisini doğrula

Migration'lar

  • Flyway veya Liquibase kullan; üretimde Hibernate auto DDL'ye asla güvenme
  • Migration'ları idempotent ve ekleyici tut; plan olmadan sütun kaldırmaktan kaçın

Veri Erişimi Testi

  • Üretimi yansıtmak için Testcontainers ile @DataJpaTest tercih et
  • Logları kullanarak SQL verimliliğini assert et: parametre değerleri için logging.level.org.hibernate.SQL=DEBUG ve logging.level.org.hibernate.orm.jdbc.bind=TRACE ayarla

Hatırla: Entity'leri yalın, sorguları kasıtlı ve transaction'ları kısa tut. Fetch stratejileri ve projections ile N+1'i önle, ve okuma/yazma yolların için indeksle.

Source repo
affaan-m/ECC
Skill path
docs/tr/skills/jpa-patterns/SKILL.md
Commit SHA
4e973d3eaf92
Repository license
MIT
Data collected