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

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