What is the significance of the @Table annotation in JPA?
@Table tells JPA which table an entity maps to and lets you set the schema, unique constraints and indexes. Learn each attribute with working examples.
2,886 posts about Java: questions with answers, tutorials and articles, newest first.
@Table tells JPA which table an entity maps to and lets you set the schema, unique constraints and indexes. Learn each attribute with working examples.
@OneToMany, @ManyToOne and @ManyToMany map entity relationships to foreign keys and join tables. See examples, fetch defaults, cascading rules and common mistakes.
Map one-to-one, one-to-many, many-to-one and many-to-many relationships in JPA, and learn the owning side, mappedBy, fetch types and cascade rules.
Extend JpaRepository for your entity and Spring Data generates CRUD, paging and query methods for you. This guide covers setup and examples.
SpringExtension is the JUnit 5 extension that loads Spring contexts and injects beans into tests. Learn when you need it and how it differs from SpringRunner.
Learn to build JUnit 5 extensions with lifecycle callbacks, parameter resolvers and conditions, and register them with @ExtendWith or @RegisterExtension.
@ExtendWith registers JUnit Jupiter extensions on tests. See Mockito and Spring usage, a custom extension, parameter injection and how it replaces @RunWith.
@Nested lets you organise JUnit 5 tests into inner classes with their own setup and display names. Includes a full example and lifecycle order.
@BeforeEach and @AfterEach set up and clean up every JUnit 5 test. See practical patterns with Mockito and databases, plus ordering rules and pitfalls.
Learn Mockito verification: verify call counts, arguments with ArgumentCaptor, call order with InOrder, and how to avoid brittle over-verified tests.
Unit tests check one class in isolation with mocks; integration tests check real components together. See examples, a comparison table and when to use each.
Compare MockMvc, TestRestTemplate and WebTestClient, then test status codes, JSON bodies, errors and security against a real database in Spring.
@Rollback controls whether a transactional Spring test rolls back or commits. See class and method usage, @Commit, TestTransaction and cases where rollback does not apply.
Annotate tests with @Transactional so Spring rolls back each test automatically, and learn when to commit, flush or clean up manually.
@DirtiesContext marks the cached Spring test context as dirty so it is rebuilt for the next test. Learn when to use it and what to use instead.
Three ways to write custom assertions for JUnit tests: static helpers, AssertionFailedError and fluent AssertJ assertion classes.
@TestPropertySource overrides configuration for a Spring test with property files or inline values. See its precedence, usage and alternatives.
Create application-test.properties, activate it with ActiveProfiles, swap beans with Profile or TestConfiguration, and use Testcontainers for real databases.
H2 gives Spring tests a fast in-memory database. Learn setup with @DataJpaTest and @Sql, plus when Testcontainers is the safer choice.
Use H2 with @DataJpaTest and @SpringBootTest for fast, isolated database tests in Spring Boot, and learn where in-memory databases differ from production.