2

我有 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    
    ......
}
4

1 回答 1

1

是的

@Entity
@AccessType("field")
@Table(name = "A")
@XStreamAlias("A")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class A implements SerializableObject {

    @Id
    @JoinColumn(name = "X_ID", nullable = false)
    @ManyToOne(targetEntity = X.class)
    protected X x;

    @Id
    @JoinColumn(name = "Y_ID", nullable = false)
    @ManyToOne(targetEntity = Y.class)
    protected y;
...........
}

PSbut rhus 没有解决缓存未命中

于 2012-05-02T11:51:59.893 回答