Set up a database management system for our Spring Boot project using Hibernate ORM. The task includes configuring the database connection, creating entity classes, and seeding the database with initial data. This setup will help streamline data operations and ensure application can interact with the database efficiently.
Tasks
Database Configuration
Configure the application to connect to a PostgreSQL database by default.
Allow the setup to be flexible for configuring any database.
Add necessary dependencies in pom.xml (Spring Data JPA, PostgreSQL Driver).
Update application.properties with database connection details (URL, username, password, etc.).
Set spring.jpa.hibernate.ddl-auto=update for automatic schema management.
Entity Classes
Create entity classes for User, Profile, Organisation, and Product.
Annotate the classes with Hibernate/JPA annotations (@Entity, @Table, @Id, etc.).
Define relationships between entities:
A user has one profile (@OneToOne).
A user has many products (@OneToMany).
A user belongs to many organisations (@ManyToMany).
An organisation has many users (@ManyToMany).
Repository Layer
Create repository interfaces extending JpaRepository for each entity.
Define custom queries if necessary.
Seeding the Database
Create a data seeding component to initialize the database with sample data.
Ensure the seeding process runs only once during application startup.
Seed the database with the following data:
At least 2 users.
At least 2 products per user.
At least 3 organisations.
User one belongs to 2 of the organisations.
User two belongs to all 3 organisations.
Validation Steps
- Ensure the following tables and constraints are created:
* Users
* Profiles
* Organisations
* Products
- Validate the relationships:
* A user has one profile.
* A user has many products.
* A user belongs to many organisations.
* An organisation has many users.
Description
Set up a database management system for our Spring Boot project using Hibernate ORM. The task includes configuring the database connection, creating entity classes, and seeding the database with initial data. This setup will help streamline data operations and ensure application can interact with the database efficiently.
Tasks
Database Configuration
Configure the application to connect to a PostgreSQL database by default.
Allow the setup to be flexible for configuring any database.
Add necessary dependencies in pom.xml (Spring Data JPA, PostgreSQL Driver).
Update application.properties with database connection details (URL, username, password, etc.).
Set spring.jpa.hibernate.ddl-auto=update for automatic schema management.
Entity Classes
Create entity classes for User, Profile, Organisation, and Product.
Annotate the classes with Hibernate/JPA annotations (@Entity, @Table, @Id, etc.).
Define relationships between entities:
Repository Layer
Create repository interfaces extending JpaRepository for each entity.
Define custom queries if necessary.
Seeding the Database
Create a data seeding component to initialize the database with sample data.
Ensure the seeding process runs only once during application startup.
Seed the database with the following data:
Validation Steps
Api Endoint
GET] api/v1/users/user_one_id
GET] api/v1/users/user_two_id
Testing
Acceptance Criteria:
Assignees
@lurldgbodex