Repository Layer Application Properties Integration Testing

Week 5 Reading

Database Design and Integration Part 2

Study the repository layer, application properties, table relationships, and integration testing so the database stack works cleanly from configuration to persistence.

Topics4Database integration concepts
Objectives12Learning goals across the week
Review Prompts8Questions for revision
Focus Areas4Layering, config, relationships, testing

Week 5 Content

Repository layer, configuration, relationships, and testing

Each topic combines objectives, discussion notes, a diagram, an applied example, and review questions so the book can support reading and teaching.

Repositories, config, relationships, tests
Topic 4.6 3 deep dives 2 review questions

Repository Layer

The repository layer isolates database access behind a dedicated interface so services and controllers can stay focused on business logic.

Topic Build
Objectives3
Deep dives3
Review prompts2
Learning Objectives
  • Explain the purpose of the repository layer in a layered architecture.
  • Describe how repositories interact with entities and services.
  • Recognize why data access should be separated from business rules.
Discussion Notes
01

Repositories provide a clean boundary for saving, finding, updating, and deleting data.

02

A service can call a repository without knowing the underlying SQL or persistence details.

03

Repository interfaces are often implemented by Spring Data JPA, which reduces boilerplate.

04

This separation makes the application easier to test and easier to maintain.

Team Insights

The repository layer should only deal with persistence concerns. Business validation belongs in services, while HTTP handling belongs in controllers.

An interface defines what data access operations are available. The implementation can be generated by Spring Data or written manually when needed.

A dedicated repository layer reduces coupling, keeps code organized, and allows different storage strategies to be swapped later with less disruption.
Workflow Diagram Click to zoom
Repository Layer Flow ControllerHTTP requests ServiceBusiness logic RepositoryPersist data DatabaseTables
Applied Example

A student management system uses StudentRepository to save student records, find a student by matric number, and delete inactive accounts without putting SQL in the controller.

Review Questions
  1. Why should database access live in a repository layer?
  2. How does a repository help keep the rest of the app simpler?
Key Takeaways
  • Repositories hide persistence details.
  • Services call repositories to work with data.
  • Loose coupling improves testing and maintenance.
Topic 4.7 3 deep dives 2 review questions

Application Properties

Application properties store configuration values that control database connection settings, JPA behavior, and runtime options for the application.

Topic Build
Objectives3
Deep dives3
Review prompts2
Learning Objectives
  • Describe the role of application.properties in Spring applications.
  • Recognize common database and JPA settings.
  • Explain why external configuration is better than hard-coded values.
Discussion Notes
01

Application properties keep configuration outside the Java source code.

02

Database URL, username, password, and driver settings are often configured here.

03

JPA and Hibernate options can also be tuned to control schema updates and SQL logging.

04

Profiles allow different settings for development, testing, and production environments.

Team Insights

Hard-coded configuration is difficult to change safely. Property files and environment variables make deployments more flexible and less error-prone.

Connection strings, dialect selection, and schema behavior are all controlled from configuration so the application can point to the right database environment.

A development profile might use a local database, while test and production profiles use separate settings. That keeps environments isolated and predictable.
Workflow Diagram Click to zoom
Configuration Flow Propertiesapp settings Profiledev/test/prod DatasourceURL, user, pass JPAHibernate options
Applied Example

During development, a team sets the local database URL and enables SQL logging in application.properties, while the production profile uses secure credentials from the deployment platform.

Review Questions
  1. Why is application.properties useful in a Spring project?
  2. What settings would you expect to see for a database connection?
Key Takeaways
  • Configuration should live outside source code.
  • Application properties control database and JPA behavior.
  • Profiles help separate environments.
Topic 4.8 3 deep dives 2 review questions

Table Relationships

Table relationships define how records connect, including one-to-one, one-to-many, and many-to-many structures across the database.

Topic Build
Objectives3
Deep dives3
Review prompts2
Learning Objectives
  • Explain common relationship types used in relational databases.
  • Describe how foreign keys and join tables support relationships.
  • Recognize when a relationship should be modeled as one-to-many or many-to-many.
Discussion Notes
01

One-to-many relationships are common when one parent record can own many child records.

02

Many-to-many relationships usually need a join table to store the link between two tables.

03

Foreign keys enforce the connection between related records.

04

Correct relationships make queries easier and reduce data duplication.

Team Insights

A single parent such as a customer can relate to many children such as orders. The child table usually holds the foreign key.

When both sides can have many matches, a join table stores each pair. That avoids repeating the same relationship in multiple places.

Good relationship design should reflect how the application actually reads data. Clear structure makes joins predictable and maintainable.
Workflow Diagram Click to zoom
Table Relationship Types CustomerOne OrderMany OrderItemJoin table 1 : * * : *
Applied Example

A course registration system stores one student with many registrations and one course with many registrations, using a registration table to join both sides cleanly.

Review Questions
  1. When do you need a join table?
  2. Why are foreign keys important in related tables?
Key Takeaways
  • Relationships connect tables logically.
  • Many-to-many relationships need an intermediate table.
  • Foreign keys enforce links between records.
Topic 4.9 3 deep dives 2 review questions

Testing Integration

Integration testing checks that repository, configuration, and database pieces work together as a complete application flow.

Topic Build
Objectives3
Deep dives3
Review prompts2
Learning Objectives
  • Explain what integration testing verifies in a database-backed application.
  • Recognize the difference between unit tests and integration tests.
  • Understand why repository testing should use the application context or test database.
Discussion Notes
01

Integration tests load part or all of the application stack and verify that components work together.

02

Repository tests often use annotations such as @DataJpaTest or a dedicated test database.

03

Testing configuration, repositories, and relationships together catches problems that unit tests can miss.

04

Reliable integration tests help protect the project when schema or data-access code changes.

Team Insights

Unit tests isolate one class or method, while integration tests confirm that several parts of the system cooperate correctly.

Repository tests should check real persistence behavior such as query results, entity mapping, and key constraints rather than only mocking everything out.

When the repository layer, properties, and schema are covered by tests, the team can refactor with more confidence.
Workflow Diagram Click to zoom
Testing Integration Flow Test@DataJpaTest ContextSpring app RepoReal queries Test DBVerify state
Applied Example

A test class loads the Spring context, inserts a sample course registration into the test database, and verifies that the repository can fetch it back with the expected relationship data.

Review Questions
  1. What does integration testing prove that unit tests may not?
  2. Why is a test database useful for repository tests?
Key Takeaways
  • Integration tests verify combined behavior.
  • Repository tests should use realistic application context.
  • Testing protects data access changes from regressions.
8 questions True / False Auto-marked

Week 5 Quiz

Enter your details, start the quiz, and then review the score with the correct answers shown underneath.

Quiz Rules
Total items8
Pass mark70%
GradingInstant

Enter your Name and Matric No, then press Start Quiz to begin the attempt.

The quiz stays hidden until you start it, just like Quiz 1.

Press Start Quiz to open the questions and begin the attempt.