Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

spring-data-jdbc

/spring-data-jdbc

Wspiera Spring Data JDBC do prostego dostępu do bazy bez złożoności JPA: agregaty, repozytoria, własne zapytania i wzorce DDD.

Licencja
MIT
Ostatnia zmiana repozytorium
21.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
2
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
1
Przestarzałość

Brak sygnałów. Repozytorium zmienione 21.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Wspiera Spring Data JDBC do prostego dostępu do bazy bez złożoności JPA: agregaty, repozytoria, własne zapytania i wzorce DDD.

Wyzwalacze z opisu

spring data jdbcsimple database accessno JPAaggregate rootsDDD with JDBClightweight ORM@MappedCollection
Oryginalny opis (EN)

Spring Data JDBC for simple, lightweight database access without JPA complexity. Covers aggregates, repositories, custom queries, and DDD patterns. USE WHEN: user mentions "spring data jdbc", "simple database access", "no JPA", "aggregate roots", "DDD with JDBC", "lightweight ORM", "@MappedCollection" DO NOT USE FOR: JPA/Hibernate features - use `spring-data-jpa` instead, reactive database - use `spring-r2dbc` instead, NoSQL - use respective skills

Jak działa

  1. Why Spring Data JDBC over JPA?
  2. Dependencies
  3. Entity Mapping
  4. Aggregate Design
  5. Repository Pattern
  6. Schema
  7. When NOT to Use This Skill
  8. Anti-Patterns
  9. Quick Troubleshooting
  10. Best Practices
Sekcje z nagłówków SKILL.md, w oryginale · 157 linii, 591 słów
Podgląd SKILL.md
---
name: spring-data-jdbc
description: |
  Spring Data JDBC for simple, lightweight database access without JPA complexity.
  Covers aggregates, repositories, custom queries, and DDD patterns.

  USE WHEN: user mentions "spring data jdbc", "simple database access", "no JPA",
  "aggregate roots", "DDD with JDBC", "lightweight ORM", "@MappedCollection"

  DO NOT USE FOR: JPA/Hibernate features - use `spring-data-jpa` instead,
  reactive database - use `spring-r2dbc` instead, NoSQL - use respective skills
allowed-tools: Read, Grep, Glob, Write, Edit
---
# Spring Data JDBC - Quick Reference

> **Full Reference**: See [advanced.md](advanced.md) for custom row mappers, ID generation, auditing, event listeners, and Testcontainers integration.

> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `spring-data-jdbc` for comprehensive documentation.

## Why Spring Data JDBC over JPA?

| Spring Data JDBC | Spring Data JPA |
|------------------|-----------------|
| No lazy loading | Lazy loading |
| No dirty checking | Auto dirty checking |
| No session/cache | First-level cache |
| Explicit SQL | Generated SQL |
| Fast startup | Slower startup |

## Dependencies

```xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
```

## Entity Mapping

```java
@Table("users")
public class User {
    @Id
    private Long id;
    private String username;
    private String email;

    @Column("created_at")
    private LocalDateTime createdAt;
}
```

## Aggregate Design

```java
@Table("orders")
public class Order {
    @Id
    private Long id;
    private Long customerId;  // Reference by ID, not entity
    private OrderStatus status;

    @MappedCollection(idColumn = "order_id")
    private Set<OrderItem> items = new HashSet<>();

    public void addItem(Long productId, int quantity, BigDecimal price) {
        items.add(new OrderItem(productId, quantity, price));
    }

    public BigDecimal getTotal() {
        return items.stream()
            .map(OrderItem::getSubtotal)
            .reduce(BigDecimal.ZERO, BigDecimal::add);
    }
}

// Aggregate member (no @Id - lifecycle managed by root)
public class OrderItem {
    private Long productId;
    private int quantity;
    private BigDecimal unitPrice;

    public BigDecimal getSubtotal() {
        return unitPrice.multiply(BigDecimal.valueOf(quantity));
    }
}
```

## Repository Pattern

```java
public interface OrderRepository extends CrudRepository<Order, Long> {

    List<Order> findByCustomerId(Long customerId);
    List<Order> findByStatus(OrderStatus status);

    @Query("SELECT * FROM orders WHERE status = :status ORDER BY created_at DESC LIMIT :limit")
    List<Order> findRecentByStatus(OrderStatus status, int limit);

    @Modifying
    @Query("UPDATE orders SET status = :newStatus WHERE status = :oldStatus AND created_at < :before")
    int updateOldOrders(OrderStatus oldStatus, OrderStatus newStatus, LocalDateTime before);

    boolean existsByCustomerIdAndStatus(Long customerId, OrderStatus status);
}
```

## Schema

```sql
CREATE TABLE orders (
    id BIGSERIAL PRIMARY KEY,
    customer_id BIGINT NOT NULL,
    status VARCHAR(50) NOT NULL
);

CREATE TABLE order_item (
    order_id BIGINT NOT NULL REFERENCES orders(id) ON DELETE CASCADE,
    product_id BIGINT NOT NULL,
    quantity INT NOT NULL,
    unit_price DECIMAL(10, 2) NOT NULL
);
```

## When NOT to Use This Skill

- **Need lazy loading** - Use `spring-data-jpa` for complex entity graphs
- **Reactive applications** - Use `spring-r2dbc` for non-blocking access
- **Complex ORM features** - Use JPA for second-level cache, dirty checking

## Anti-Patterns

| Anti-Pattern | Problem | Solution |
|--------------|---------|----------|
| JPA-style entity graphs | Not supported | Design proper aggregates |
| Embedding other aggregates | Coupling | Reference by ID only |
| Large aggregates | Performance issues | Keep aggregates small |
| Missing CASCADE on FK | Orphan records | Add ON DELETE CASCADE |

## Quick Troubleshooting

| Problem | Diagnostic | Fix |
|---------|------------|-----|
| Entity not saved | Check @Id generation | Configure ID callback or auto-increment |
| Children not persisted | Check @MappedCollection | Add idColumn properly |
| Column not mapped | Check naming | Use @Column for custom names |
| Transaction not working | Check @Transactional | Ensure Spring proxy |

## Best Practices

| Do | Don't |
|----|-------|
| Design proper aggregates | Use JPA-style entity graphs |
| Reference other aggregates by ID | Embed other aggregate roots |
| Keep aggregates small | Create huge aggregate graphs |
| Use immutable value objects | Mutate embedded objects directly |

## Production Checklist

- [ ] Aggregate boundaries defined
- [ ] Schema matches entity mapping
- [ ] Indexes on query columns
- [ ] Foreign keys with CASCADE
- [ ] Transaction boundaries clear
- [ ] Connection pool configured

## Reference Documentation
- [Spring Data JDBC Reference](https://docs.spring.io/spring-data/jdbc/reference/)
Pliki w paczce (2)
  • SKILL.md 5 KB
  • advanced.md 5 KB

Wersje

W bazie nie ma innych skilli o nazwie spring-data-jdbc.

Migawka bazy z 13.11.2026 · wersja paczki b0634d0aabe3 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100spring-boot-data-ddd
    Implementuje warstwę danych Spring Boot 4 dla Domain-Driven Design: agregaty JPA lub JDBC, repozytoria Spring Data, serwisy transakcyjne, projekcje, audyt encji i EntityGraph przeciw N+1.
  • 100spring-r2dbc
    Wspiera reaktywny dostęp do bazy w Spring Data R2DBC (Spring Boot 3.x): R2dbcRepository, DatabaseClient, transakcje reaktywne i integrację z WebFlux.
  • 100spring-boot-data-access
    Optymalizuje JPA, Hibernate i dostęp do bazy w Spring Boot, przy implementacji encji i repozytoriów.
  • 100312-frameworks-spring-data-jdbc
    Pomaga używać Spring Data JDBC z rekordami Java: repozytoria, niemodyfikowalne aktualizacje i relacje agregatów.
  • 100spring-data-jpa
    Wspiera Spring Data JPA w aplikacjach Spring Boot: repozytoria, encje, relacje, zapytania, paginacja i audyt, na podstawie wzorców z projektów produkcyjnych.
  • 100spring-data-jpa
    Generuje i refaktoryzuje encje, repozytoria, projekcje i zapytania JPA w Spring Boot 4 z Hibernate 7.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.