我正试图以一对一的关系从父实体中获取延迟子实体。
我尝试在父方添加@LazyToOne(LazyToOneOption.NO_PROXY)
。我也尝试了@MapsId
,如post& post2。但是,儿童实体仍然热切期待。下面是我的实体课程,我应该做些什么来实现懒惰。
@Entity
@Table(name = "POST")
public class Post {
@Id
@GeneratedValue
private Long id;
private String title;
@OneToOne(mappedBy = "post", cascade = CascadeType.ALL,
fetch = FetchType.LAZY, optional = false)
private PostDetails details;
//getters and setters
}
@Entity
@Table(name = "POST_DETAILS")
public class PostDetails {
@Id
private Long id;
private String comment;
@OneToOne(fetch = FetchType.LAZY)
@MapsId
private Post post;
//getters and setters
}
(Post)session.get(Post.class, 1L);