I am following this book on Spring Boot with domain driven design where the author models a Cargo entity which has a bunch of attributes. The two attributes in question are the numerical key and a business key (bookingId). The Cargo entity is as below
**Cargo.java**
package whatever;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
@Entity
@Getter @Setter
public class Cargo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Embedded
private BookingId bookingId; // Business Identifier
}
**BookingId.java**
package whatever;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Column;
import javax.persistence.Embeddable;
@Embeddable
@Getter @Setter
public class BookingId {
@Column(name="booking_id")
private String bookingId;
}
As you can see, the author has modelled the business key as an embedded object. What are the benefits of embedding an attribute inside another object? Why don't we just have a String variable called bookingId in Cargo class and enforce a uniqueness constraint on it?