开发者

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜