JPA的Secondary table

@SecondaryTable,@SecondaryTables允许你把一个entity映射到多表上,有点类似于主从表的概念,其实也是一对一或者一对多关系映射的简化版.举个简单例子,如Customer有属性street,city,state.这三个属性构成了顾客的地址,我们希望把此 3个属性映射到另一张表上,作为主表的从表,此表跟主表就是一对一关系,通过address_id进行主键关联.那么,我们的Customer来应该像这样:
@Entity
@Table(name = CUSTOMER)
@SecondaryTable(name = EMBEDDED_ADDRESS,pkJoinColumns={@PrimaryKeyJoinColumn(name = ADDRESS_ID)})
public class Customer implements java.io.Serializable
{
private int id;
private String first;
private String last;
private String street;
private String city;
private String state;
private String zip;
........

........
@SecondaryTable的na

你可能感兴趣的:(jpa)