Search code examples
hibernateormjpaembeddable

How hibernate store embeddable obj


kind of stupid question but i didn't find the answer anywhere. How @Embeddable object is stored in the database, is it kind of OneToOne with FK or... For example if i have:

@Entity
public class User {
   private Long id;

   @Id 
   public Long getId() { return id; }
   public void setId(Long id) { this.id = id; }


   private Address address;

   @Embedded 
   public Address getAddress() { return address; }
   public void setAddress() { this.address = address; }
}


@Embeddable
public class Address {
   private String street1;

   public String getStreet1() { return street1; }
   public void setStreet1() { this.street1 = street1; }
}

How the table(s) should look like?


Solution

  • The embedded object's fields are added as columns to the table of the owning Entity.

    So you will have a table User with fields id and street1.