Spring Jpa Testing logo

Spring Jpa Testing

Organization
spring-ai-community
spring-jpa-testing

@DataJpaTest requires TestEntityManager + flush()/clear() before assertions — without this, tests read from Hibernate L1 cache and pass falsely. Read before writing any JPA test. Triggers: @DataJpaTest, JpaRepository, TestEntityManager, @ServiceConnection, Testcontainers, @Modifying, Hibernate 6/7, @AutoConfigureTestDatabase, flush and clear in tests, @Transactional in tests, jakarta.persistence.EntityManager.

Overview

Publisherspring-ai-community
Repositoryspring-testing-skills
Skill namespring-jpa-testing
Stars
52
Forks
2
Bundled files
4
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 4 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by spring-ai-community on GitHub. Read the source before you install it.

Installation

Install the Spring Jpa Testing AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/spring-ai-community/spring-testing-skills/tree/main/skills/spring-jpa-testing
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/spring-ai-community/spring-testing-skills.git /tmp/spring-testing-skills
mkdir -p .claude/skills
cp -r /tmp/spring-testing-skills/skills/spring-jpa-testing .claude/skills/spring-jpa-testing
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Spring Jpa Testing in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Spring Jpa Testing on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Spring Jpa Testing is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Spring JPA Testing

CRITICAL: @DataJpaTest requires TestEntityManager for test data setup and flush()+clear() before read assertions. Tests that skip this read from the Hibernate L1 cache and produce false-passing tests — the query is never executed against the database. See "Critical Rules" below.

Signals: @DataJpaTest, JpaRepository, EntityManager, TestEntityManager, @ServiceConnection, PostgreSQLContainer, @AutoConfigureTestDatabase, @Modifying, clearAutomatically, Testcontainers, Hibernate 6, Hibernate 7

Tested With

  • Spring Boot 3.2+ / Spring Boot 4.x
  • Spring Framework 6.x / Spring Framework 7.x
  • Hibernate 6.x / Hibernate 7.x
  • JUnit 5, Testcontainers 1.19+

Critical Rules — Always Apply in @DataJpaTest

1. Use TestEntityManager for test data setup — never Mockito mocks. @DataJpaTest provides a real in-memory database. Mocking the repository defeats the purpose. Use @Autowired TestEntityManager em and em.persist() / em.persistAndFlush() to insert test data. Do NOT use the repository under test for setup — that creates circular logic where a bug in the repository masks both setup and assertion failures.

2. Always flush() and clear() before read assertions. After persisting test data, call em.flush() then em.clear() before querying through the repository. Without flush, SQL may never reach the database. Without clear, the repository returns entities from the Hibernate L1 cache — your query is never actually executed against the database.

java
@DataJpaTest
class OrderRepositoryTest {
    @Autowired TestEntityManager em;
    @Autowired OrderRepository orders;

    @Test
    void findByStatus_returnsMatching() {
        em.persist(new Order("pending"));
        em.persist(new Order("shipped"));
        em.flush();   // SQL hits the database
        em.clear();   // L1 cache evicted — forces real DB read

        List<Order> result = orders.findByStatus("pending");
        assertThat(result).hasSize(1);
    }
}

See references/transactional-tests.md for full patterns including @Modifying bulk updates, constraint violation testing, and the @Transactional trap.

Do NOT Use This Skill When

  • Testing REST controllers or HTTP endpoints → use spring-mvc-testing
  • Testing authentication, authorization, CSRF, JWT, or OAuth2 → use spring-security-testing
  • Testing reactive repositories (R2DBC) or WebClient → use spring-webflux-testing
  • Writing pure unit tests without a Spring context → use spring-testing-fundamentals
  • Setting up AssertJ assertions or Mockito stubs → use spring-testing-fundamentals

When to Read References

SituationRead
Setting up @DataJpaTest with Testcontainers and @ServiceConnectionreferences/testcontainers.md
Choosing between @DataJpaTest and @SpringBootTestreferences/testcontainers.md
Debugging @Transactional rollback issues, flush/clear problems, test isolationreferences/transactional-tests.md
Writing test patterns: derived queries, @Query, pagination, specs, projections, auditingreferences/transactional-tests.md
Lazy loading works in test but fails in production, N+1 issuesreferences/lazy-loading-tests.md
Testing SINGLE_TABLE inheritance, read-only repositories, @QueryHint pitfallsreferences/lazy-loading-tests.md
Hibernate 6.x or 7.x migration failures, Jakarta packages, sequence naming, ClassCastExceptionreferences/hibernate-6-migration.md
Boot 3.x → 4.x test package import changesreferences/hibernate-6-migration.md

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Spring Jpa Testing AI skill do?

@DataJpaTest requires TestEntityManager + flush()/clear() before assertions — without this, tests read from Hibernate L1 cache and pass falsely. Read before writing any JPA test. Triggers: @DataJpaTest, JpaRepository, TestEntityManager, @ServiceConnection, Testcontainers, @Modifying, Hibernate 6/7, @AutoConfigureTestDatabase, flush and clear in tests, @Transactional in tests, jakarta.persistence.EntityManager.

Why use Spring Jpa Testing on TypingMind?

Because you install it once and use it with any model. Spring Jpa Testing is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Spring Jpa Testing in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/spring-ai-community/spring-testing-skills/tree/main/skills/spring-jpa-testing. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Spring Jpa Testing?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Spring Jpa Testing?

As many as you like. As long as a model supports skills, you can use Spring Jpa Testing with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Spring Jpa Testing AI skill free?

Yes. It is published on GitHub by spring-ai-community under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇