Question

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?

Was it helpful?

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top