How can I make a JPA OneToOne relation lazy

前端 未结 10 1837
暖寄归人
暖寄归人 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:13

    The basic idea behing the XToOnes in Hibernate is that they are not lazy in most case.

    One reason is that, when Hibernate have to decide to put a proxy (with the id) or a null,
    it has to look into the other table anyway to join. The cost of accessing the other table in the database is significant, so it might as well fetch the data for that table at that moment (non-lazy behaviour), instead of fetching that in a later request that would require a second access to the same table.

    Edited: for details, please refer to ChssPly76 's answer. This one is less accurate and detailed, it has nothing to offer. Thanks ChssPly76.

提交回复
热议问题