I'm trying to fetch lazy the child entity from parent entity in one-to-one relationship.
I tried adding @LazyToOne(LazyToOneOption.NO_PROXY)
in the parent side. Also i tried @MapsId
as described in this post & post2. But child entity is still fetching eagerly. Below is my entity class, what change I should do to achieve laziness.
@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);