Spring Boot REST Service & JPA Code Review
Deep code review for Spring Boot services examining transaction boundaries, JPA N+1 queries, concurrency, and validation.
Interactive Prompt Playground
{{CODE}}{{SPRING_VERSION}}{{DATABASE}}{{CONTEXT}}You are an elite Java and Spring Boot architect conducting a rigorous code review.
Review the following Spring Boot service/repository code against production standards:
```java
@Service
public class OrderService {
@Autowired
private OrderRepository orderRepository;
@Autowired
private PaymentClient paymentClient;
public Order processOrder(Long userId, OrderRequest request) {
Order order = new Order(userId, request.getItems());
orderRepository.save(order);
paymentClient.charge(userId, order.getTotal());
order.setStatus(OrderStatus.COMPLETED);
return orderRepository.save(order);
}
}
```
Context & Environment:
- Spring Boot Version: Spring Boot 3.3 / Java 21
- Database / Persistence: PostgreSQL 16 with Spring Data JPA
- Business Requirements / Context: E-commerce order checkout endpoint handling financial transactions
Perform a comprehensive review focusing on the following critical dimensions:
1. **Transaction & JPA Semantics**:
- Verify proper `@Transactional` boundaries and propagation.
- Flag potential Hibernate N+1 select queries, unindexed queries, or eager-loading traps.
- Check entity lifecycle management (detached entity mutations, dirty checking).
2. **Concurrency & Thread Safety**:
- Check if singleton Spring components maintain mutable state or non-thread-safe fields.
- Inspect optimistic/pessimistic locking strategies where concurrent updates may occur.
3. **Error Handling & API Contracts**:
- Ensure exceptions are mapped to meaningful HTTP status codes via `@ControllerAdvice` or problem details.
- Verify input validation (`@Valid`, `@NotNull`, Jakarta bean validation).
4. **Security & Input Sanitization**:
- Ensure parameterized queries prevent SQL injection and inputs are sanitized.
- Check role-based access control annotations (`@PreAuthorize`).
Output your review formatted into:
- 🚨 **Critical Issues (Must Fix)**: Bugs, concurrency flaws, or major performance bottlenecks with code diffs.
- ⚠️ **Warnings & Code Smells**: Suboptimal patterns, transaction risks, or missing validations.
- 💡 **Optimization Suggestions**: Clean code improvements and idiomatic Spring Boot idioms.
- ✅ **Refactored Solution**: The complete corrected code.How to Use This Prompt
- Paste your Service, Controller, or Entity repository code into the code block.
- Specify your Spring Boot and Java version (e.g., Spring Boot 3.3 / Java 21).
- Mention any specific performance or concurrency requirements in the context field.
- Copy and submit the customized prompt to Claude, Cursor, or your preferred LLM.
Engineering Tips & Best Practices
- Never run remote HTTP calls inside an active @Transactional method as it exhausts DB connection pools.
- Ask the LLM to provide integration test scenarios using Testcontainers alongside the review.
What This Prompt Inspects
Key failure modes, design principles, and quality standards evaluated during execution.
Transaction Isolation & Propagation
Ensures external API calls are not executed inside open DB transactions holding connections.
JPA N+1 & Fetch Graph
Inspects relationship mappings to prevent cascading queries during serialization.
Bean Thread-Safety
Validates that Spring Singleton beans do not store request-scoped mutable state.
Exception Translation
Verifies domain exceptions translate to RFC 7807 Problem Details.
Realistic Usage Scenario
Scenario: Reviewing a financial checkout service with unhandled payment client rollbacks and missing transactional annotations.
Sample Input Values:
SprintKit Workflow Integrations
Complementary interactive tools and workflows across SprintKit to accelerate your engineering process.
Related Prompts
Explore related developer prompts in this workflow domain.
Database Deadlock & Concurrency Race Condition Investigator
Diagnose Postgres/MySQL transaction deadlocks, lock contention, and concurrent update race conditions.
Legacy Code Safe Refactoring with Characterization Tests
Safely modernize fragile legacy codebases using Martin Fowler refactoring patterns and golden master tests.