How can I make a JPA OneToOne relation lazy

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

    To get lazy loading working on nullable one-to-one mappings you need to let hibernate do compile time instrumentation and add a @LazyToOne(value = LazyToOneOption.NO_PROXY) to the one-to-one relation.

    Example Mapping:

    @OneToOne(fetch = FetchType.LAZY)  
    @JoinColumn(name="other_entity_fk")
    @LazyToOne(value = LazyToOneOption.NO_PROXY)
    public OtherEntity getOther()
    

    Example Ant Build file extension (for doing the Hibernate compile time instrumentation):

     
     
     
    
     
       
       
     
    
     
       
         
           
         
       
     
    
     
       
         
           
         
       
    
       
         
           
           
         
       
    
    

提交回复
热议问题