关闭

@AssociationOverrides @AttributeOverride @AttributeOverride

554人阅读 评论(0) 收藏 举报
分类:

@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;
    ...
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1359次
    • 积分:48
    • 等级:
    • 排名:千里之外
    • 原创:3篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档