我有 ID APK 的实体 A 有两个长字段,即其他实体的 ID。因此,我在对实体 A 执行添加/删除操作时发现 Hibernate 缓存未命中,为了避免这种情况,我想使用实体而不是 long。
@Entity
@AccessType("field")
@Table(name = "A")
@XStreamAlias("A")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class A {
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "x", column = @Column(name = "X_ID")),
@AttributeOverride(name = "y", column = @Column(name = "Y_ID"))})
private APK id;
...................
}
@AccessType("field")
@Embeddable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class APK implements Serializable {
protected long x= 0;//this is id of another entity
protected long y= 0;//this is id of another entity
......
}