How can I make a JPA OneToOne relation lazy

前端 未结 10 1834
暖寄归人
暖寄归人 2020-11-22 03:34

In this application we are developing, we noticed that a view was particularly slow. I profiled the view and noticed that there was one query executed by hibernate which too

10条回答
  •  野性不改
    2020-11-22 04:37

    This question is quite old, but with Hibernate 5.1.10, there are some new better comfortable solution.

    Lazy loading works except for the parent side of a @OneToOne association. This is because Hibernate has no other way of knowing whether to assign a null or a Proxy to this variable. More details you can find in this article

    • You can activate lazy loading bytecode enhancement
    • Or, you can just remove the parent side and use the client side with @MapsId as explained in the article above. This way, you will find that you don’t really need the parent side since the child shares the same id with the parent so you can easily fetch the child by knowing the parent id .

提交回复
热议问题