Data Model Reference
This page documents all JPA entities in thesvc-envio-encomienda microservice. The data model represents the core business objects: clients, shipments, packages, and branches.
Entity Overview
The system consists of four main entities:- Cliente - Customer/sender information
- Envio - Shipment tracking and logistics
- Encomienda - Physical package details
- Sucursal - Branch office locations
Cliente Entity
Table:clientesSource:
org.jchilon3mas.springcloud.svc.envio.encomienda.entidades.ClienteLocation: svc-envio-encomienda/src/main/java/org/jchilon3mas/springcloud/svc/envio/encomienda/entidades/Cliente.java:13 Represents a customer who sends packages through the system.
Fields
id - Long
id - Long
Type:
Annotations:
Description: Primary key, auto-generated.
LongAnnotations:
@Id, @GeneratedValue(strategy = GenerationType.IDENTITY)Description: Primary key, auto-generated.
dni - String
dni - String
Type:
Annotations:
Description: National identity document number. Must be unique, exactly 8 characters.
StringAnnotations:
@Column(unique = true, nullable = false, length = 8)Description: National identity document number. Must be unique, exactly 8 characters.
The DNI serves as a natural unique identifier for customers in Peru.
nombreCompleto - String
nombreCompleto - String
Type:
Annotations:
Description: Full name of the customer. Required field.
StringAnnotations:
@Column(nullable = false)Description: Full name of the customer. Required field.
correo - String
correo - String
Type:
Annotations:
Description: Email address. Must be unique across all customers.
StringAnnotations:
@Column(unique = true)Description: Email address. Must be unique across all customers.
telefono - String
telefono - String
Type:
Annotations:
Description: Phone number, typically 9 digits for mobile phones.
StringAnnotations:
@Column(length = 9)Description: Phone number, typically 9 digits for mobile phones.
Annotations
@Entity- Marks this as a JPA entity@Data- Lombok annotation generating getters, setters, toString, equals, and hashCode@NoArgsConstructor- Generates no-argument constructor@AllArgsConstructor- Generates constructor with all fields@Table(name = "clientes")- Maps to theclientestable
Envio Entity
Table:enviosSource:
org.jchilon3mas.springcloud.svc.envio.encomienda.entidades.EnvioLocation: svc-envio-encomienda/src/main/java/org/jchilon3mas/springcloud/svc/envio/encomienda/entidades/Envio.java:17 Core entity representing a shipment from origin to destination branch.
Fields
id - Long
id - Long
Type:
Annotations:
Description: Primary key, auto-generated.
LongAnnotations:
@Id, @GeneratedValue(strategy = GenerationType.IDENTITY)Description: Primary key, auto-generated.
codigoSeguimiento - String
codigoSeguimiento - String
Type:
Annotations:
Description: Unique tracking code for the shipment. Format:
StringAnnotations:
@Column(unique = true, nullable = false, updatable = false)Description: Unique tracking code for the shipment. Format:
ENV-{timestamp}. Auto-generated by @PrePersist method.This field cannot be updated after creation (
updatable = false).remitente - Cliente
remitente - Cliente
Type:
Annotations:
Description: The customer sending the package. Many shipments can belong to one customer.
ClienteAnnotations:
@ManyToOne, @JoinColumn(name = "remitente_id", nullable = false)Description: The customer sending the package. Many shipments can belong to one customer.
encomienda - Encomienda
encomienda - Encomienda
Type:
Annotations:
Description: The physical package being shipped. One-to-one relationship with cascade operations.
EncomiendaAnnotations:
@OneToOne(cascade = CascadeType.ALL), @JoinColumn(name = "encomienda_id", referencedColumnName = "id", unique = true, nullable = false)Description: The physical package being shipped. One-to-one relationship with cascade operations.
sucursalOrigen - Sucursal
sucursalOrigen - Sucursal
Type:
Annotations:
Description: Branch where the package originates.
SucursalAnnotations:
@ManyToOne, @JoinColumn(name = "sucursal_origen_id", nullable = false)Description: Branch where the package originates.
sucursalDestino - Sucursal
sucursalDestino - Sucursal
Type:
Annotations:
Description: Destination branch where package will arrive.
SucursalAnnotations:
@ManyToOne, @JoinColumn(name = "sucursal_destino_id", nullable = false)Description: Destination branch where package will arrive.
nombreDestinatario - String
nombreDestinatario - String
Type:
Annotations:
Description: Full name of the recipient.
StringAnnotations:
@Column(nullable = false)Description: Full name of the recipient.
dniDestinatario - String
dniDestinatario - String
Type:
Annotations:
Description: Recipient’s identity document number.
StringAnnotations:
@Column(nullable = false, length = 20)Description: Recipient’s identity document number.
placa - String
placa - String
Type:
Annotations:
Description: Vehicle license plate for transportation. Optional field.
StringAnnotations:
@Column(length = 7)Description: Vehicle license plate for transportation. Optional field.
fechaEnvio - LocalDateTime
fechaEnvio - LocalDateTime
Type:
Annotations:
Description: Timestamp when shipment was registered.
LocalDateTimeAnnotations:
@Column(nullable = false)Description: Timestamp when shipment was registered.
fechaEntrega - LocalDateTime
fechaEntrega - LocalDateTime
Type:
Annotations:
Description: Timestamp when package was delivered. Null until delivery.
LocalDateTimeAnnotations:
@Column(name = "fecha_entrega")Description: Timestamp when package was delivered. Null until delivery.
contrasenaEntrega - String
contrasenaEntrega - String
Type:
Annotations:
Description: 4-digit delivery password for pickup verification.
StringAnnotations:
@Column(nullable = false, length = 4)Description: 4-digit delivery password for pickup verification.
precio - double
precio - double
Type:
Annotations:
Description: Total shipping cost in local currency.
doubleAnnotations:
@Column(nullable = false)Description: Total shipping cost in local currency.
estado - EstadoEnvio
estado - EstadoEnvio
Type:
Annotations:
Default:
Description: Current shipment status.Possible values:
EstadoEnvio (enum)Annotations:
@Enumerated(EnumType.STRING), @Column(nullable = false)Default:
EstadoEnvio.PENDIENTEDescription: Current shipment status.Possible values:
PENDIENTE- Registered, awaiting dispatchEN_TRANSITO- In transit to destinationDISPONIBLE- Available for pickup at destinationENTREGADO- Successfully deliveredCANCELADO- Shipment cancelled
Stored as STRING in database for readability and forward compatibility.
Lifecycle Methods
@PrePersist - generarCodigoSeguimiento()
@PrePersist - generarCodigoSeguimiento()
Location: svc-envio-encomienda/src/main/java/org/jchilon3mas/springcloud/svc/envio/encomienda/entidades/Envio.java:67Automatically generates tracking code before entity persistence:
Only generates if
codigoSeguimiento is null, allowing manual override if needed.Encomienda Entity
Table:encomiendasSource:
org.jchilon3mas.springcloud.svc.envio.encomienda.entidades.EncomiendaLocation: svc-envio-encomienda/src/main/java/org/jchilon3mas/springcloud/svc/envio/encomienda/entidades/Encomienda.java:13 Represents the physical package or parcel being shipped.
Fields
id - Long
id - Long
Type:
Annotations:
Description: Primary key, auto-generated.
LongAnnotations:
@Id, @GeneratedValue(strategy = GenerationType.IDENTITY)Description: Primary key, auto-generated.
peso - double
peso - double
Type:
Annotations:
Description: Package weight in kilograms. Required field.
doubleAnnotations:
@Column(nullable = false)Description: Package weight in kilograms. Required field.
Weight is used for pricing calculation and vehicle assignment.
dimensiones - String
dimensiones - String
Type:
Annotations:
Description: Package dimensions, typically in format “LxWxH” (e.g., “10x20x30” cm).
StringAnnotations:
@Column(nullable = false)Description: Package dimensions, typically in format “LxWxH” (e.g., “10x20x30” cm).
descripcion - String
descripcion - String
Type:
Annotations:
Description: Description of package contents. Maximum 500 characters.
StringAnnotations:
@Column(nullable = false, length = 500)Description: Description of package contents. Maximum 500 characters.
envio - Envio
envio - Envio
Type:
Annotations:
Description: Back-reference to the parent shipment. Bidirectional relationship.
EnvioAnnotations:
@OneToOne(mappedBy = "encomienda")Description: Back-reference to the parent shipment. Bidirectional relationship.
Sucursal Entity
Table:sucursalesSource:
org.jchilon3mas.springcloud.svc.envio.encomienda.entidades.SucursalLocation: svc-envio-encomienda/src/main/java/org/jchilon3mas/springcloud/svc/envio/encomienda/entidades/Sucursal.java:13 Represents a physical branch office location.
Fields
id - Long
id - Long
Type:
Annotations:
Description: Primary key, auto-generated.
LongAnnotations:
@Id, @GeneratedValue(strategy = GenerationType.IDENTITY)Description: Primary key, auto-generated.
codigoSucursal - String
codigoSucursal - String
Type:
Annotations:
Description: Branch code identifier (e.g., “LIM-01”, “ARE-02”).
StringAnnotations:
@Column(nullable = false)Description: Branch code identifier (e.g., “LIM-01”, “ARE-02”).
nombreSucursal - String
nombreSucursal - String
Type:
Annotations:
Description: Branch name or location identifier.
StringAnnotations:
@Column(nullable = false)Description: Branch name or location identifier.
direccion - String
direccion - String
Type:
Annotations:
Description: Physical street address of the branch.
StringAnnotations:
@Column(nullable = false)Description: Physical street address of the branch.
ciudad - String
ciudad - String
Type:
Annotations:
Description: City where the branch is located.
StringAnnotations:
@Column(nullable = false)Description: City where the branch is located.
Relationships Summary
Key Relationship Rules
- Cliente → Envio: One customer can have many shipments (ManyToOne)
- Envio → Encomienda: Each shipment has exactly one package (OneToOne with cascade)
- Envio → Sucursal: Each shipment has origin and destination branches (ManyToOne)
The cascade setting on Envio → Encomienda means deleting a shipment will automatically delete its package.
Database Schema Notes
Naming Conventions
- Table names are plural:
clientes,envios,encomiendas,sucursales - Foreign key columns use
_idsuffix:remitente_id,encomienda_id - Enum values stored as strings for clarity
Indexes
Data Validation
All entities use Lombok’s@Data annotation which generates:
toString()- for loggingequals()andhashCode()- for collections- Getters and setters - for property access
Consider adding
@EqualsAndHashCode(onlyExplicitlyIncluded = true) with @EqualsAndHashCode.Include on id fields to avoid issues with lazy-loaded relationships.