Entity Relationship Overview
DriveX uses JPA (Java Persistence API) to manage four core entities and their relationships:User Entity
The User entity represents customer accounts and administrative users.Entity Definition
Fields Reference
Primary key, auto-generated using IDENTITY strategy
Unique username for the user account
User’s email address, used as login identifier
BCrypt hashed password (never store plaintext passwords)
User’s first name (maps to
first_name column)User’s last name (maps to
last_name column)Contact phone number
User role (e.g., “USER”, “ADMIN”)
Account activation status
URL to user’s profile image (maps to
profile_image column)Vehicle Entity
The Vehicle entity represents cars and motorcycles available for rent.Entity Definition
Fields Reference
Primary key, auto-generated
Unique reference code for the vehicle (non-nullable)
Vehicle manufacturer (e.g., “FERRARI”, “TOYOTA”)
Vehicle model name
Horsepower rating
Range in kilometers (for electric vehicles)
Average fuel consumption (maps to
average_consumption column)Detailed vehicle description
Daily rental price
Manufacturing year
Fuel type (e.g., “GASOLINE”, “DIESEL”, “ELECTRIC”)
Total kilometers driven
Additional features and equipment
Number of doors
Type of vehicle (e.g., “CAR”, “MOTORCYCLE”)
Current promotional offers
One-to-many relationship with vehicle images. Cascades all operations and removes orphaned images.
Vehicle-Image Relationship
The Vehicle entity has a one-to-many relationship with VehicleImage:- CascadeType.ALL: All JPA operations (persist, merge, remove) cascade to images
- orphanRemoval = true: Automatically deletes images when removed from the list
- @JsonIgnoreProperties(“vehicle”): Prevents circular reference in JSON serialization
Rental Entity
The Rental entity tracks vehicle reservations and bookings.Entity Definition
Fields Reference
Foreign key reference to User entity
Foreign key reference to Vehicle entity
Rental period start date
Rental period end date
Total rental price (precision 10, scale 2 for currency)
Current rental status, defaults to RESERVED
Rental Status Enum
The RentalStatus enum defines the rental lifecycle:RESERVED
RESERVED
Initial state when a user books a vehicle. Vehicle is held but rental hasn’t started.
ACTIVE
ACTIVE
Rental is currently in progress. User has picked up the vehicle.
COMPLETED
COMPLETED
Rental period has ended and vehicle has been returned.
CANCELLED
CANCELLED
Booking was cancelled before becoming active.
Automatic Timestamps
The Rental entity uses JPA lifecycle callbacks for automatic timestamp management:Favorite Entity
The Favorite entity implements a many-to-many relationship between Users and Vehicles for wishlists.Entity Definition
Key Features
Unique Constraint
Prevents duplicate favorites with
@UniqueConstraint on (user_id, vehicle_id)Many-to-One Relationships
Both user and vehicle use
@ManyToOne allowing multiple favorites per user and per vehicleUsage Example
The unique constraint at the database level ensures a user cannot favorite the same vehicle multiple times.
Brand Enum
The Brand enum provides a comprehensive list of supported vehicle manufacturers:View Complete Brand List
View Complete Brand List
The Brand enum includes over 100 manufacturers across categories:
- Luxury and sports cars (Ferrari, Lamborghini, Porsche, etc.)
- General automotive brands (Toyota, Ford, Honda, etc.)
- Motorcycle manufacturers (Yamaha, Ducati, Harley-Davidson, etc.)
- Electric vehicle brands (Tesla, Lucid, Polestar, etc.)
- Classic and historic brands (DeLorean, Packard, etc.)
Database Naming Conventions
DriveX uses a mixed naming strategy:| Java Code | Database Column |
|---|---|
| camelCase | snake_case |
firstName | first_name |
vehicleType | vehicle_type |
createdAt | created_at |