Skip to content

rrezartprebreza/spring-boot-skills / skills/spring-boot-3/spring-data-jpa

spring-data-jpa

Verified

Use when generating JPA entities, repositories, queries, or anything touching the persistence layer. Covers entity conventions, N+1 prevention, projections, and query patterns.

FileKindSize
SKILL.mdskill md6.2 KB
agents/openai.yamlconfig197 B
examples/bad-entity.javaother999 B
examples/good-entity.javaother2.0 KB

examples/good-entity.java

View on GitHub
// GOOD — UUID ID, STRING enum, LAZY fetch, behavior methods, no public setters

@Entity
@Table(name = "orders", indexes = {
    @Index(name = "idx_orders_status", columnList = "status"),
    @Index(name = "idx_orders_customer_email", columnList = "customer_email")
})
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Order {

    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    @Column(updatable = false, nullable = false)
    private UUID id;

    @Column(name = "customer_email", nullable = false)
    private String customerEmail;

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private OrderStatus status;

    @OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<OrderItem> items = new ArrayList<>();

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;

    @CreationTimestamp
    @Column(updatable = false)
    private Instant createdAt;

    @UpdateTimestamp
    private Instant updatedAt;

    @Version
    private Long version;

    public static Order create(String customerEmail, User user) {
        Order order = new Order();
        order.customerEmail = customerEmail;
        order.user = user;
        order.status = OrderStatus.PENDING;
        return order;
    }

    public void addItem(Product product, int quantity) {
        if (status != OrderStatus.PENDING)
            throw new IllegalStateException("Cannot add items to order in status: " + status);
        items.add(OrderItem.create(this, product, quantity));
    }

    public void confirm() {
        if (status != OrderStatus.PENDING)
            throw new IllegalStateException("Can only confirm PENDING orders");
        this.status = OrderStatus.CONFIRMED;
    }

    public void ship() {
        if (status != OrderStatus.CONFIRMED)
            throw new IllegalStateException("Can only ship CONFIRMED orders");
        this.status = OrderStatus.SHIPPED;
    }
}
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall