0

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?

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145

2 Answers2

2

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.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
1

It's very simple: all columns from the embedded object will be merged into columns of the parent, resulting with a single table. In your example you will end up with a table User containing columns: id and street1. So embedded objects are basically a way to logically group columns within one table.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674