How can I make a JPA OneToOne relation lazy

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

    If the child entity is used readonly, then it's possible to simply lie and set optional=false. Then ensure that every use of that mapped entity is preloaded via queries.

    public class App {
      ...
      @OneToOne(mappedBy = "app", fetch = FetchType.LAZY, optional = false)
      private Attributes additional;
    

    and

    String sql = " ... FROM App a LEFT JOIN FETCH a.additional aa ...";
    

    ... maybe even persisting would work...

提交回复
热议问题