title: Modelling a business key as an attribute vs an embedded object
body: <p>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</p>
  <pre><code>**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
  }
  
  </code></pre>
  <pre><code>**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=&quot;booking_id&quot;)
      private String bookingId;
  }
  
  </code></pre>
  <p>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?</p>