@AssociationOverrides @AttributeOverride @AttributeOverride

@AssociationOverrides @AttributeOverride @AttributeOverride这三个注解就是用于修改从父类继承的属性和映射关系

如果使用 @AssociationOverride,则 Employee 表包含以下列:

  • ID

  • VERSION

  • ADDR_ID

  • WAGE

如果不使用 @AssociationOverride,则 Employee 表包含以下列:

  • ID

  • VERSION

  • ADDRESS

  • WAGE

示例 1-1 @MappedSuperclass

@MappedSuperclass
public class Employee {
@Id protected Integer id;
@Version protected Integer version;
@ManyToOne protected Address address;
    ...
}

示例 1-2 @AssociationOverride

@Entity@AssociationOverride(name="address", joinColumns=@JoinColumn(name="ADDR_ID"))public class PartTimeEmployee extends Employee {    @Column(name="WAGE")    protected Float hourlyWage;
    ...
}

如果使用 @AttributeOverride,则 Employee 表包含以下列:

  • ID

  • VERSION

  • ADDR_STRING

  • WAGE

如果不使用 @AttributeOverride,则 Employee 表包含以下列:

  • ID

  • VERSION

  • ADDRESS

  • WAGE

示例 1-4 @MappedSuperclass

@MappedSuperclass
public class Employee {
@Id protected Integer id;
@Version protected Integer version;
protected String address;
    ... 
}

示例 1-5 @AttributeOverride

@Entity
@AttributeOverride(name="address", column=@Column(name="ADDR_STRING"))
public class PartTimeEmployee extends Employee {
@Column(name="WAGE")
protected Float hourlyWage;
    ...
}
@Entity
@AssociationOverrides({
@AssociationOverride(name="address", joinColumn=@Column(name="ADDR_ID")),
@AssociationOverride(name="id", joinColumn=@Column(name="PTID"))
})
public class PartTimeEmployee extends Employee {
@Column(name="WAGE")
protected Float hourlyWage;
    ...
}

阅读更多
个人分类: 数据库
想对作者说点什么? 我来说一句

hibernate的ID生成策略

hiberate

chao821 chao821

2016-10-31 17:48:32

阅读数:133

没有更多推荐了,返回首页

不良信息举报

@AssociationOverrides @AttributeOverride @AttributeOverride

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭