Master Spring Data JPA - repositories, queries, relationships, transactions, and performance
Provides Spring Data JPA expertise for repository patterns, custom queries, and entity relationships. Triggers when you're building database access layers, defining entities, or optimizing queries with N+1 prevention and fetch strategies.
/plugin marketplace add pluginagentmarketplace/custom-plugin-spring-boot/plugin install spring-boot-assistant@pluginagentmarketplace-spring-bootThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/config.yamlassets/schema.jsonreferences/GUIDE.mdreferences/PATTERNS.mdscripts/validate.pyComprehensive guide to data access with Spring Data JPA including repository patterns, custom queries, and performance optimization.
This skill covers everything needed for production-ready database access with Spring Data JPA.
| Name | Type | Required | Default | Validation |
|---|---|---|---|---|
database | enum | ✗ | postgresql | postgresql | mysql | h2 |
migration_tool | enum | ✗ | flyway | flyway | liquibase | none |
fetch_strategy | enum | ✗ | lazy | lazy | eager |
@Entity, @Table, @Id, relationshipsJpaRepository, derived queries@Transactional, propagation@Query with JPQL and native SQL@CreatedDate, @LastModifiedDate@Entity
@Table(name = "orders")
@EntityListeners(AuditingEntityListener.class)
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true, nullable = false)
private String orderNumber;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customer_id", nullable = false)
private Customer customer;
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true)
private List<OrderItem> items = new ArrayList<>();
@CreatedDate
private LocalDateTime createdAt;
@Version
private Long version;
public void addItem(OrderItem item) {
items.add(item);
item.setOrder(this);
}
}
public interface OrderRepository extends JpaRepository<Order, Long>,
JpaSpecificationExecutor<Order> {
Optional<Order> findByOrderNumber(String orderNumber);
@Query("SELECT o FROM Order o JOIN FETCH o.items WHERE o.customer.id = :customerId")
List<Order> findByCustomerWithItems(@Param("customerId") Long customerId);
@EntityGraph(attributePaths = {"items", "customer"})
Optional<Order> findWithDetailsById(Long id);
@Modifying
@Query("UPDATE Order o SET o.status = :status WHERE o.id = :id")
int updateStatus(@Param("id") Long id, @Param("status") OrderStatus status);
}
public class OrderSpecifications {
public static Specification<Order> hasStatus(OrderStatus status) {
return (root, query, cb) ->
status == null ? null : cb.equal(root.get("status"), status);
}
public static Specification<Order> createdAfter(LocalDateTime date) {
return (root, query, cb) ->
date == null ? null : cb.greaterThan(root.get("createdAt"), date);
}
}
// Usage
Specification<Order> spec = Specification
.where(OrderSpecifications.hasStatus(status))
.and(OrderSpecifications.createdAfter(since));
Page<Order> orders = orderRepository.findAll(spec, pageable);
| Issue | Diagnosis | Fix |
|---|---|---|
| N+1 queries | Multiple SELECTs | Use @EntityGraph or JOIN FETCH |
| LazyInitializationException | Access outside session | Use @Transactional or DTO |
| Data not saved | Missing @Transactional | Add to service method |
□ Enable SQL logging: spring.jpa.show-sql=true
□ Check for N+1 with hibernate.generate_statistics
□ Verify @Transactional on write operations
□ Review fetch types (LAZY vs EAGER)
@DataJpaTest
@Testcontainers
class OrderRepositoryTest {
@Container
@ServiceConnection
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15");
@Autowired
private OrderRepository orderRepository;
@Test
void shouldFindByOrderNumber() {
Order order = new Order();
order.setOrderNumber("ORD-001");
orderRepository.save(order);
Optional<Order> found = orderRepository.findByOrderNumber("ORD-001");
assertThat(found).isPresent();
}
}
Skill("spring-data-jpa")
| Version | Date | Changes |
|---|---|---|
| 2.0.0 | 2024-12-30 | Specifications, auditing, performance patterns |
| 1.0.0 | 2024-01-01 | Initial release |
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.