我有很多参考/查找实体,这些实体很少更改,并且大多数使用二级缓存。
当请求父实体时,我当前正在急切地加载这些实体(几乎在所有关联类型中-太多)。我之所以这样获取的原因,通常是父实体需要这些实体。
所以我的问题是:应该使用这样的二级缓存还是在需要时加入这些参考/查找表?
这里是一个例子:
父实体
@Entity
@Table
public class SomeEntity implements Serializable {
@Id
@Column(name = "id")
private Long id;
//Some other fields...
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "foo_id", referencedColumnName = "id")
private Foo foo;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "bar_id", referencedColumnName = "id")
private Bar bar;
}
参考/查找实体
@Entity
@Table
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Foo implements Serializable {
@Id
@Column(name = "id")
private Short id;
@Column(name = "description", nullable = false)
private String description;
}
//Bar is the same as Foo