Agent skill
spring-data-jpa-repo-creator
Creates Spring Data JPA repositories following best practices.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/spring-data-jpa-repo-creator
SKILL.md
Spring Data JPA Repository Creator
Instructions
The following are key principles to follow while creating Spring Data JPA Repositories:
- Make sure to create the recommended package structure for Spring Boot projects
- Create repositories only for aggregate roots
- Use
@Querywith JPQL for custom queries - Prefer meaningful method names over long Spring Data JPA finder methods
- Use constructor expressions or Projections for read operations
- Use default methods for convenience operations
Example: EventRepository
File: events/domain/EventRepository.java
interface EventRepository extends JpaRepository<EventEntity, EventId> {
@Query("""
SELECT e FROM EventEntity e
WHERE e.startDatetime > :now
ORDER BY e.startDatetime ASC
""")
List<EventEntity> findUpcomingEvents(@Param("now") Instant now);
@Query("""
SELECT e FROM EventEntity e
WHERE e.code = :code
""")
Optional<EventEntity> findByCode(@Param("code") EventCode code);
// Convenience methods using default interface methods
default EventEntity getByCode(EventCode eventCode) {
return this.findByCode(eventCode)
.orElseThrow(() -> new ResourceNotFoundException("Event not found with code: " + eventCode));
}
}
Enable JPA Auditing
Enable JPA Auditing support to automatically populate createdAt and updatedAt fields.
- Add
@CreatedDateand@LastModifiedDateannotations to yourBaseEntityclass. - Add
@EntityListeners(AuditingEntityListener.class)to yourBaseEntityclass. - Create a Spring
@Configurationclass and add@EnableJpaAuditingannotation.
package dev.sivalabs.meetup4j.shared;
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.Instant;
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity {
@Column(name = "created_at", nullable = false, updatable = false)
@CreatedDate
protected Instant createdAt;
@Column(name = "updated_at", nullable = false)
@LastModifiedDate
protected Instant updatedAt;
// Getters and setters
}
Enable JPA Auditing in your application configuration:
@Configuration
@EnableJpaAuditing
public class JpaConfig {
}
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?