【发布时间】:2016-04-22 18:00:56
【问题描述】:
我正在使用带有 jpa 的 hibernate 4.0,我有一个可以从数据库加载大量数据的一对多关系,我将其设置为延迟加载(如下面的代码)
为了保持历史,当我想删除 B 时,我从不从数据库中删除它,我只是将“关闭”属性设置为 true...
问题是如果我尝试使用以下方式加载所有 A 实例:
session.createCriteria(A.class).list();
对于每个实例,休眠将延迟加载标记为已关闭的 B。我想知道是否有任何注释可以定义为只加载那些“关闭”为假的注释。 避免在我用来加载 A 的每个代码中指定它
public class A {
@Id
private Integer id;
private String fullName;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, targetEntity = B.class)
@LazyCollection(LazyCollectionOption.TRUE)
private List<B> series = new Vector<B>();
}
public class B {
@Id
private Integer id;
private Boolean closed;
private Date createdDate;
/**lots of other things**/
}
【问题讨论】:
标签: java hibernate annotations one-to-many