1

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);
Vlad Mihalcea
  • 103,297
  • 39
  • 432
  • 788
Manoj
  • 4,979
  • 16
  • 48
  • 81

0 Answers0