Services with Databases
The following services require database configuration:Auth Service
Manages OAuth2/OIDC data, user authentication, and session storage
User Service
Stores user profiles and related data
Client Service
Manages client/customer information
Vehicle Service
Stores vehicle inventory and details
Purchase-Sale Service
Tracks transactions and purchase/sale records
Standard Database Configuration
All data-access services use this base configuration pattern:JPA Configuration
Open In View
Controls whether JPA sessions remain open during view rendering. Always set to
false in SGIVU services.Hibernate DDL Mode (Profile-Specific)
Different profiles use different DDL strategies:Development Profile
Hibernate schema generation mode. Use
validate to verify schema matches entities without modifying the database.Enables SQL statement logging. Set to
true in development for debugging.Production Profile
Production profiles disable SQL logging for performance and security. Schema validation ensures entities match the database structure.
Flyway Migration Configuration
SGIVU uses Flyway for database schema versioning and migrations.Base Configuration
Enables Flyway migrations. Set to
true for all services with databases.Classpath location of migration scripts. Standard location is
classpath:db/migration.Creates a baseline version when migrating an existing database. Controlled by
FLYWAY_BASELINE_ON_MIGRATE environment variable.Version number for the baseline. Set to
0 to mark the starting point.Validates applied migrations before running new ones. Set to
true to ensure migration integrity.Profile-Specific Flyway Settings
Development Profile
Prevents Flyway from dropping all database objects. Set to
false in development to allow clean operations.Production Profile
Production profiles explicitly disable clean operations to prevent accidental data loss.
Database Connection Configuration
Database connection details are profile-specific and environment-driven:Development Profile
Production Profile
Environment Variable Patterns
Environment Variable Patterns
Each service uses prefixed environment variables:Auth Service:
DEV_AUTH_DB_HOST/PROD_AUTH_DB_HOSTDEV_AUTH_DB_PORT/PROD_AUTH_DB_PORTDEV_AUTH_DB_NAME/PROD_AUTH_DB_NAMEDEV_AUTH_DB_USERNAME/PROD_AUTH_DB_USERNAMEDEV_AUTH_DB_PASSWORD/PROD_AUTH_DB_PASSWORD
DEV_USER_DB_HOST/PROD_USER_DB_HOST- (same pattern for other variables)
Migration Script Organization
Flyway migrations should be placed insrc/main/resources/db/migration with the following naming convention:
Examples
Version numbers should be sequential integers. Flyway applies migrations in order and tracks which versions have been applied.
Complete Service Examples
Auth Service (sgivu-auth.yml)
The Auth Service additionally uses JDBC-backed sessions, which requires database configuration for the
SPRING_SESSION table.User Service (sgivu-user.yml)
Vehicle Service (sgivu-vehicle.yml)
Client Service (sgivu-client.yml)
Purchase-Sale Service (sgivu-purchase-sale.yml)
Session Storage (Auth Service)
The Auth Service uses JDBC-backed session storage:Session storage mechanism. Set to
jdbc for database-backed sessions.Controls session table creation. Set to
never since Flyway manages the schema.Name of the session table. Standard value is
SPRING_SESSION.Cron expression for expired session cleanup. Runs every 15 minutes.
Troubleshooting
Flyway baseline errors
Flyway baseline errors
Error: This creates a baseline version and allows Flyway to start managing an existing database.
Found non-empty schema without schema history tableSolution: Set the FLYWAY_BASELINE_ON_MIGRATE environment variable to true for the initial migration:Flyway validation failures
Flyway validation failures
Error:
Validate failed: Migration checksum mismatchCauses:- Migration file was modified after being applied
- Different migration file with same version number
- Never modify applied migrations - create a new migration instead
- If in development, clean the database and re-run migrations
- If in production, repair the Flyway schema history table
JPA lazy loading exceptions
JPA lazy loading exceptions
Error:
LazyInitializationException: could not initialize proxy - no SessionCause: Attempting to access lazy-loaded relationships outside a transaction.Solution: With open-in-view: false, you must:- Explicitly fetch required relationships in your queries
- Use
@Transactionalon service methods that load entities - Use DTO projections to avoid lazy loading issues
Connection pool exhaustion
Connection pool exhaustion
Symptoms:
- Slow response times
- Timeout errors
- “Connection is not available” exceptions
- Ensure transactions are properly closed (use
@Transactional) - Configure connection pool settings (HikariCP)
- Check for connection leaks in application code
- Increase pool size if needed (with proper resource analysis)
Related Configuration
Spring Configuration
JPA and session management settings
Environment Variables
Database connection environment variables
Service Configuration
Individual service database requirements
Deployment
Database setup in different environments