Package com.example.springrest.models
package com.example.springrest.models
JPA Entities that represent the core domain model of the application.
Entities are classes mapped to database tables using JPA annotations
(such as Entity
, Table
,
and Column
). They define the persistent state
of the system.
Key characteristics of entities:
- Persistence mapping: Each entity corresponds to a table row, and each field maps to a database column.
- Identifiers: Entities usually have a primary key
(e.g.,
@Id Long id
) to uniquely identify each record. - Relationships: Entities may define relationships
(e.g.,
@OneToMany
,@ManyToOne
) between tables. - Business rules: Some validation or domain rules may live here, though complex logic is often delegated to the service layer.
Important: Entities should generally not be exposed directly
in API endpoints. Instead, use DTOs from the dto
package to define
the contract with external clients. This avoids leaking internal details,
improves security, and allows flexibility in evolving the API.
Example in this package: Product
-
Classes