Bird
0
0

How can you ensure the test uses the correct database dialect and schema?

hard📝 Application Q9 of 15
Spring Boot - Testing Spring Boot Applications
You want to test a repository method that returns a list of users filtered by age using @DataJpaTest. The method uses a native SQL query. How can you ensure the test uses the correct database dialect and schema?
AConfigure <code>spring.jpa.properties.hibernate.dialect</code> and provide schema initialization scripts in <code>src/test/resources</code>
BAdd <code>@AutoConfigureTestDatabase(replace = Replace.NONE)</code> to use the production database
CUse <code>@MockBean</code> to mock the repository and avoid database calls
DSet <code>spring.jpa.hibernate.ddl-auto=none</code> to disable schema creation
Step-by-Step Solution
Solution:
  1. Step 1: Set correct Hibernate dialect

    Configure spring.jpa.properties.hibernate.dialect in test properties to match the database dialect.
  2. Step 2: Provide schema scripts

    Place schema initialization scripts in src/test/resources to create tables for native queries.
  3. Final Answer:

    Configure dialect and provide schema scripts in test resources -> Option A
  4. Quick Check:

    Dialect + schema scripts ensure native query works in tests [OK]
Quick Trick: Set dialect and schema scripts for native query tests [OK]
Common Mistakes:
  • Using production DB in tests
  • Mocking repository instead of testing real DB
  • Disabling schema creation without providing schema

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes