Skip to main content

MODULE 4 - Databases in Production

Module Objectives​

This module will enable you to:

  • Install and configure PostgreSQL
  • Understand the difference between Jakarta and Javax Persistence
  • Master Hibernate and DDL strategies
  • Use Lombok to reduce boilerplate code
  • Migrate an application from H2 to PostgreSQL
  • Manage multiple databases (MySQL, SQL Server, Oracle)

Module Content​

Theory​

This module is divided into 4 theoretical chapters that you must read before proceeding to the practical work:

Chapter 1: PostgreSQL - Installation and Configuration​

  • What is PostgreSQL?
  • Installation on Windows/Mac/Linux
  • Administration tools (pgAdmin, DBeaver)
  • Creating databases and users
  • Configuring Spring Boot for PostgreSQL
  • Connection and testing
  • Security and best practices

Chapter 2: Jakarta vs Javax Persistence​

  • History: Java EE → Jakarta EE
  • Differences between javax.persistence and jakarta.persistence
  • Migration: when and how?
  • Compatibility with Spring Boot 2.x vs 3.x
  • Resolving common issues
  • Choosing the right version

Chapter 3: Hibernate and DDL Strategies​

  • What is Hibernate?
  • Role of Hibernate in Spring Boot
  • ddl-auto strategies in detail:
    • none: No action
    • validate: Validation only
    • update: Incremental update
    • create: Recreation at each startup
    • create-drop: Creation and deletion
  • When to use each strategy?
  • Configuring Hibernate dialect
  • SQL logs and debugging
  • Performance and optimization

Chapter 4: Lombok - Reducing Boilerplate Code​

  • What is Lombok?
  • Installation and configuration
  • Main annotations:
    • @Data
    • @Getter / @Setter
    • @NoArgsConstructor / @AllArgsConstructor
    • @RequiredArgsConstructor
    • @Builder
    • @ToString
    • @EqualsAndHashCode
  • Advantages and disadvantages
  • Best practices
  • Compatibility with JPA

Practical Work​

TP4.1: PostgreSQL Migration and Production​

Objective: Migrate an H2 application to PostgreSQL with Lombok

Content:

  • Installation and configuration of PostgreSQL
  • Migration from H2 to PostgreSQL
  • Use of Jakarta Persistence
  • Application of Lombok to all entities
  • Configuration of DDL strategies
  • Tests and validation
  • Migration to other DBs (MySQL, SQL Server, Oracle)

Estimated Duration: 4-6 hours

Prerequisites:

  • Module 2 completed (TP2.1 and TP2.2)
  • Module 3 completed (TP3.1 - CRUD Architecture)
  • All chapters of Module 4 read

Level: Intermediate to Advanced


Prerequisites​

Required Knowledge​

Before starting this module, you should master:

✅ Module 2 (complete):

  • Spring Initializr
  • Project structure
  • Configuration
  • Basic annotations
  • Repositories and basic JPA
  • In-memory and persistent H2

✅ Module 3 (complete):

  • 3-layer architecture
  • Data validation
  • HTTP error handling
  • Complete CRUD

If you are not comfortable with these concepts, return to the previous modules.

Required Software​

  1. PostgreSQL 14+

  2. pgAdmin or DBeaver

  3. JDK 17+, Maven 3.9+, VS Code

    • Already installed since Module 2

Estimated Duration​

Theory: 8-10 hours (4 chapters)
Practice: 4-6 hours (1 complete TP with migration)
Total: 12-16 hours (2-3 sessions of 4-6 hours)


Additional Resources​

Official Documentation​


Success Criteria​

By the end of this module, you should be able to:

  • ✅ Install and configure PostgreSQL
  • ✅ Create and manage PostgreSQL databases
  • ✅ Understand the differences between Jakarta and Javax Persistence
  • ✅ Choose and configure the right Hibernate DDL strategy
  • ✅ Use Lombok to reduce boilerplate code
  • ✅ Migrate an application from H2 to PostgreSQL
  • ✅ Configure an application for multiple types of databases
  • ✅ Debug connection and configuration issues

Next Steps​

Once this module is completed, you will be ready for:

  • Module 5: Spring Core - Advanced IoC and DI
  • Module 6: Advanced Spring Data JPA (Joins, JPQL, Optimization)
  • Module 7: Security with Spring Security

Why This Module Is Important​

Development vs Production​

AspectH2 (Development)PostgreSQL (Production)
TypeIn-memory or local fileDedicated server
PerformanceLimitedHigh performance
Concurrent usersNot suitableExcellent
ToolsBasic consolepgAdmin, DBeaver
ScalabilityLowExcellent
UsageDevelopment/TestingProduction

Before Module 4​

❌ Development only (H2)
❌ Verbose code (many getters/setters)
❌ Complex manual configuration
❌ Not production-ready

After Module 4​

✅ Production-ready (PostgreSQL)
✅ Concise code (Lombok)
✅ Professional configuration
✅ Ready for deployment
✅ Sought-after skills in the industry

Pedagogical Note​

Why does this module come AFTER Module 3?

  1. Module 3 taught you robust architecture (Service Layer, Validation, Error Handling)
  2. This architecture works with any database
  3. Now that you master the architecture, you can focus on the database
  4. PostgreSQL is more demanding than H2: a solid foundation is needed before using it

Logical progression:

Module 2: Basics (simple H2)
↓
Module 3: Robust architecture (still H2)
↓
Module 4: Production (PostgreSQL) ← YOU ARE HERE
↓
Module 6: Optimization (Advanced queries)

Chapter 1 - PostgreSQL (detailed theory)