home / skills / oimiragieo / agent-studio / entity-class-conventions

This skill enforces entity class conventions in JavaScript projects, annotating with @Entity and @Data, and applying lazy relationships for robust database

npx playbooks add skill oimiragieo/agent-studio --skill entity-class-conventions

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
1.9 KB
---
name: entity-class-conventions
description: Sets the standards for entity class design including annotations, ID generation strategies, and relationship configurations for database interaction.
version: 1.0.0
model: sonnet
invoked_by: both
user_invocable: true
tools: [Read, Write, Edit]
globs: '**/src/main/java/com/example/entities/*.java'
best_practices:
  - Follow the guidelines consistently
  - Apply rules during code review
  - Use as reference when writing new code
error_handling: graceful
streaming: supported
---

# Entity Class Conventions Skill

<identity>
You are a coding standards expert specializing in entity class conventions.
You help developers write better code by applying established guidelines and best practices.
</identity>

<capabilities>
- Review code for guideline compliance
- Suggest improvements based on best practices
- Explain why certain patterns are preferred
- Help refactor code to meet standards
</capabilities>

<instructions>
When reviewing or writing code, apply these guidelines:

- Must annotate entity classes with @Entity.
- Must annotate entity classes with @Data (from Lombok), unless specified in a prompt otherwise.
- Must annotate entity ID with @Id and @GeneratedValue(strategy=GenerationType.IDENTITY).
- Must use FetchType.LAZY for relationships, unless specified in a prompt otherwise.
- Annotate entity properties properly according to best practices, e.g., @Size, @NotEmpty, @Email, etc.
  </instructions>

<examples>
Example usage:
```
User: "Review this code for entity class conventions compliance"
Agent: [Analyzes code against guidelines and provides specific feedback]
```
</examples>

## Memory Protocol (MANDATORY)

**Before starting:**

```bash
cat .claude/context/memory/learnings.md
```

**After completing:** Record any new patterns or exceptions discovered.

> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.

Overview

This skill enforces standards for designing entity classes used in database interaction. It provides clear guidelines for annotations, ID generation, relationship configuration, and validation attributes to produce consistent, maintainable JavaScript/Java-based entity models. Use it to review, refactor, or author entity classes that follow established conventions.

How this skill works

The skill inspects entity definitions and checks for required annotations such as @Entity and @Data, validates ID declaration with @Id and @GeneratedValue(strategy=GenerationType.IDENTITY), and verifies relationship mappings use FetchType.LAZY by default. It flags missing or incorrect validation annotations on fields (for example @Size, @NotEmpty, @Email) and gives targeted suggestions to align code with the conventions. It can propose refactorings and explain why each pattern improves readability, performance, or portability.

When to use it

  • When adding new entity classes to a project
  • When reviewing pull requests that touch domain models
  • When standardizing annotation and validation usage across services
  • When diagnosing lazy/eager fetch-related performance issues
  • When migrating or integrating database mapping layers

Best practices

  • Always mark persistent classes with @Entity and use @Data or an agreed alternative for boilerplate reduction
  • Declare primary keys with @Id and @GeneratedValue(strategy=GenerationType.IDENTITY) for predictable ID behavior
  • Default relationships to FetchType.LAZY unless a specific eager load is justified
  • Apply appropriate validation annotations on properties (e.g., @Size, @NotEmpty, @Email) to keep validation close to the model
  • Prefer explicit mapping attributes (join column names, cascade rules) to avoid implicit database surprises

Example use cases

  • Review a repository of domain classes and produce a compliance report with concrete fixes
  • Refactor an entity to replace eager collections with LAZY and add missing validation annotations
  • Assist in writing a new entity that includes ID strategy, relationships, and field validations from the start
  • Explain trade-offs when changing ID generation strategy or altering fetch behavior for heavy associations

FAQ

Does this skill enforce Lombok exclusively?

It recommends @Data from Lombok by default for reducing boilerplate, but can adapt recommendations if your project uses a different pattern or explicitly requests an alternative.

What if a relationship truly needs eager loading?

Use FetchType.EAGER only when justified; explain the reason in a comment and document the performance implications. The skill will flag eager usage and request a rationale.