Overview
The Furniture API data model is designed to manage a complete furniture catalog with inventory tracking, product organization, and customer reviews. The model uses JPA/Hibernate annotations with bidirectional relationships for efficient data access.Entity Relationship Diagram
Core Entities
Product
The central entity representing furniture items in the catalog. Table:products
Fields:
id(Integer) - Primary key, auto-generatedname(String) - Product namedescription(String) - Product descriptionsku(String) - Stock Keeping Unit identifiercategory_id(Integer) - Foreign key to Categoryprice(Double) - Selling pricecost_price(Double) - Cost/wholesale priceweight_kg(Double) - Product weight in kilogramsis_active(Boolean) - Active status flagcreated_at(LocalDateTime) - Creation timestamp
All child entities use
CascadeType.ALL and orphanRemoval = true, meaning when a product is deleted, all its dimensions, inventory, images, and reviews are automatically deleted.Category
Hierarchical category structure supporting parent-child relationships. Table:categories
Fields:
id(Integer) - Primary key, auto-generatedname(String) - Category namedescription(String) - Category descriptionparent_id(Integer) - Foreign key to parent category (self-referencing)is_active(Boolean) - Active status flag
Inventory
Stock management for products with tracking of available quantities and minimum levels. Table:inventory
Fields:
id(Integer) - Primary key, auto-generatedproduct_id(Integer) - Foreign key to Product (unique)quantity_available(Integer) - Current stock quantityminimum_stock_level(Integer) - Reorder thresholdlast_restocked_date(LocalDateTime) - Last restock timestamp
ProductDimensions
Physical dimensions for shipping and storage calculations. Table:product_dimensions
Fields:
id(Integer) - Primary key, auto-generatedproduct_id(Integer) - Foreign key to Product (unique)length_cm(Double) - Length in centimeterswidth_cm(Double) - Width in centimetersheight_cm(Double) - Height in centimetersdimension_unit(String) - Unit of measurementcreated_at(LocalDateTime) - Creation timestamp
Dimensions are stored separately from the main Product entity to keep the product table normalized and allow optional dimension data.
ProductImage
Multiple images per product with ordering support. Table:product_images
Fields:
id(Integer) - Primary key, auto-generatedproduct_id(Integer) - Foreign key to Productimage_url(String) - URL to the image resourcealt_text(String) - Alternative text for accessibilitydisplay_order(Integer) - Sort order for display
Use
display_order to control which image appears first in product galleries. Lower numbers typically display first.ProductReview
Customer reviews and ratings for products. Table:product_reviews
Fields:
id(Integer) - Primary key, auto-generatedproduct_id(Integer) - Foreign key to Productuser_id(Integer) - Reference to user (external system)rating(Integer) - Numeric rating (e.g., 1-5 stars)comment(String) - Review textcreated_at(LocalDateTime) - Review timestamp
The
user_id field is not a foreign key relationship in this service, suggesting user management is handled by a separate microservice.Supplier
Supplier contact information (currently independent entity). Table:suppliers
Fields:
id(Integer) - Primary key, auto-generatedname(String) - Supplier namecontact_email(String) - Email addresscontact_phone(String) - Phone numberis_active(Boolean) - Active status flag
The Supplier entity is currently independent. Future versions may link suppliers to products through a join table for many-to-many relationships.
Fetch Strategies
Lazy Loading
All relationships useFetchType.LAZY to prevent N+1 query problems:
Recommended Fetch Patterns
Fetch product with all details:Cascade Operations
CascadeType.ALL
Child entities (dimensions, inventory, images, reviews) cascade all operations:- PERSIST: Saving a product saves all children
- MERGE: Updating a product updates all children
- REMOVE: Deleting a product deletes all children
- REFRESH: Refreshing a product refreshes all children
- DETACH: Detaching a product detaches all children
Orphan Removal
Naming Conventions
Database Naming
- Tables: Plural snake_case (e.g.,
product_images,product_reviews) - Columns: Snake_case (e.g.,
category_id,created_at) - Physical Strategy:
PhysicalNamingStrategyStandardImplpreserves exact column names
JSON Naming
@JsonProperty annotations to ensure snake_case JSON serialization, consistent with the Jackson configuration.
Lombok Annotations
All entities use Lombok to reduce boilerplate:The
@Data annotation includes @ToString which may cause issues with bidirectional relationships. Consider using @ToString(exclude = "parent") for circular references.Data Integrity
Constraints
- Primary keys use
GenerationType.IDENTITY(auto-increment) - Foreign key columns use
@JoinColumnannotations - Unique constraints should be added at database level for
product_idin inventory and dimensions
Soft Deletes
Entities withis_active boolean flags support soft deletion:
- Product
- Category
- Supplier
Instead of physically deleting records, set
is_active = false to maintain referential integrity and historical data.