Prerequisites
Before configuring the database, ensure you have:- PostgreSQL 12 or higher installed
- A PostgreSQL database created
- Database credentials (username, password, host, port)
Database Configuration
Connection Settings
The application connects to PostgreSQL using JDBC. Configure the connection inapplication.properties:
The connection URL follows the format:
jdbc:postgresql://[host]:[port]/[database_name]Connection URL Parameters
For secure connections (recommended for production), add SSL parameters:JPA and Hibernate Configuration
Schema Management
The application is configured to not auto-generate database schemas:Valid options for
ddl-auto:none- No schema generation (recommended for production)validate- Validate schema, make no changesupdate- Update schema if neededcreate- Create schema, destroying previous datacreate-drop- Create schema, drop on application shutdown
Naming Strategy
The application uses standard naming conventions for database tables and columns:Open Session in View
To prevent lazy loading issues and improve performance:Disabling Open Session in View forces you to fetch all required data within the transaction boundary, which is a best practice for production applications.
Environment-Specific Configuration
Create environment profiles
Create separate property files for each environment:
application-dev.propertiesfor developmentapplication-test.propertiesfor testingapplication-prod.propertiesfor production
Complete Configuration Example
Database Dependencies
The following dependencies are required inpom.xml:
Connection Pool Configuration
For production environments, configure connection pooling:Troubleshooting
Connection Refused
If you encounter connection errors:- Verify PostgreSQL is running:
systemctl status postgresql - Check if the port is correct (default: 5432)
- Ensure the database exists:
psql -l - Verify firewall rules allow connections
SSL Connection Issues
For SSL-related errors:Schema Validation Errors
If schema validation fails:- Check that database schema matches entity definitions
- Verify naming strategy is correct
- Consider using
spring.jpa.hibernate.ddl-auto=validateto identify mismatches