我有以下JPA实体关系:
@Entity
public class Hardware {
@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationType.AUTO)
protected Long id;
@OneToOne( fetch = FetchType.LAZY, mappedBy = "parent", cascade = { CascadeType.MERGE } )
protected HardwareStatus status;
}
@Entity
public class HardwareStatus {
@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationType.AUTO)
protected Long id;
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="parent_id", nullable=false)
protected Hardware parent;
@Column(name="product_status", nullable=false)
@Enumerated(EnumType.STRING)
protected ProductStatus productStatus;
// .. lots of other fields
}
HardwareStatus记录每天在午夜左右计算一次,并包含有关该硬件的统计信息。大多数人懒得好。但是,我希望在硬件实体中可以使用其中一个字段(productStatus)而不加载整个HardwareStatus对象。有可能有类似的东西:
@Entity
public class Hardware {
@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationType.AUTO)
protected Long id;
@OneToOne( fetch = FetchType.LAZY, mappedBy = "parent", cascade = { CascadeType.MERGE } )
protected HardwareStatus status;
@Column(name="product_status", nullable=false)
// Some sort of JPA @Attribute to map to the HardwareStatus table to load just this field eagerly?
@Enumerated(EnumType.STRING)
protected ProductStatus productStatus;
}
提前致谢