@SecondaryTable主要用在主表提取成公共表,子表是自行定义,但主键仍然关联的情况,最终hibernate映射时使用两个类(集成关系),但为一个实体,保存到两个表的情况
@SecondaryTable(name = "childtable", pkJoinColumns = {@PrimaryKeyJoinColumn(name = "childid")})
- childtable标识子表的名称
- pkJoinColumns 使用join管理的字段是主键,主键名称为childid
SecondaryTable类源码的注释的案例如下:
* <pre>
* Example 1: Single secondary table with a single primary key column.
*
* @Entity
* @Table(name="CUSTOMER")
* @SecondaryTable(name="CUST_DETAIL",
* pkJoinColumns=@PrimaryKeyJoinColumn(name="CUST_ID"))
* public class Customer { ... }
*
*
* Example 2: Single secondary table with multiple primary key columns.
*
* @Entity
* @Table(name="CUSTOMER")
* @SecondaryTable(name="CUST_DETAIL",
* pkJoinColumns={
* @PrimaryKeyJoinColumn(name="CUST_ID"),
* @PrimaryKeyJoinColumn(name="CUST_TYPE")})
* public class Customer { ... }
* </pre>
网友评论