Skip to main content

User Entity

The User entity represents a library system user. Users can have a collection of books through a many-to-many relationship.

User Fields

id
UUID
required
Unique identifier for the user. Automatically generated using @PrePersist if not provided.
userName
string
The username for the user’s account.
name
string
The full name of the user.
birthDate
date
The date of birth of the user in ISO 8601 format (YYYY-MM-DD).
books
array
A list of books associated with the user. This is a many-to-many relationship managed by the user_books join table.

UUID Generation

The User entity uses the @PrePersist callback to automatically generate a UUID for the id field if one is not already set:
@PrePersist
public void prePersist() {
    if (id == null) {
        id = UUID.randomUUID();
    }
}

Relationships

  • Many-to-Many with Book: Users can have multiple books in their collection, and books can belong to multiple users. The relationship is managed by the user_books join table with the following structure:
    • user_id: Foreign key to the User entity
    • book_id: Foreign key to the Book entity
The relationship is configured with EAGER fetch type and supports PERSIST and MERGE cascade operations.

UserRequest

Data Transfer Object used for creating or updating a user.

Request Fields

userName
string
The username for the user’s account.
name
string
The full name of the user.
birthDate
date
The date of birth of the user in ISO 8601 format (YYYY-MM-DD).
bookIds
array
A list of UUIDs representing the books to be associated with the user.

Example Request

{
  "userName": "johndoe",
  "name": "John Doe",
  "birthDate": "1990-05-15",
  "bookIds": [
    "550e8400-e29b-41d4-a716-446655440000",
    "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
  ]
}

UserResponse

Data Transfer Object returned when retrieving user information.

Response Fields

id
UUID
required
Unique identifier of the user.
userName
string
The username for the user’s account.
name
string
The full name of the user.
birthDate
date
The date of birth of the user in ISO 8601 format (YYYY-MM-DD).
bookIds
array
A list of UUIDs representing the books associated with the user.

Example Response

{
  "id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
  "userName": "johndoe",
  "name": "John Doe",
  "birthDate": "1990-05-15",
  "bookIds": [
    "550e8400-e29b-41d4-a716-446655440000",
    "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
  ]
}

Build docs developers (and LLMs) love