Basic Tutorial
Queries
A One-to-One relationship means one entity is associated with exactly one other entity.
Example:
✅ A User has exactly one Profile
✅ A Profile belongs to exactly one User
User and Profile EntitiesWe'll create a bidirectional relationship where both User and Profile reference each other.
✅ @OneToOne(cascade = CascadeType.ALL) → Ensures changes in User also apply to Profile.
✅ @JoinColumn(name = "profile_id") → Defines the foreign key column in the User table.
Table name : profile
| id | bio | phone |
|---|
Table name : user
| id | name | profile_id |
|---|
Once the application is running, test the endpoints:
http://localhost:8080/profiles
http://localhost:8080/profiles
http://localhost:8080/profiles/{profileID}
http://localhost:8080/profiles
http://localhost:8080/profiles/{profileID}
Once the application is running, test the endpoints:
http://localhost:8080/users
http://localhost:8080/users
http://localhost:8080/users/{userID}
http://localhost:8080/users
http://localhost:8080/users/{userID}
http://localhost:8080/users/existingProfile/{profileID}
http://localhost:8080/users/existingUserProfile/{profileID}/{userID}
http://localhost:8080/users/{userID}/profile/update-name?newProfileName=Mobile Developer
http://localhost:8080/users/{userID}/profile