Version 4

    Introduction

     

    This document describes how Hibernate currently behaves in Hibernate ORM master branch with various mappings for lazy @OneToOne/@ManyToOne.

     

    It also describes possible improvements.

     

    Unidirectional one-to-one:

     

    @Entity

    public class Owner {

         @OneToOne( fetch = FetchType.LAZY )

         private Lazy lazy;

    }

     

    Join Column@LazyToOne Mappinghibernate.enhancer.enableLazyInitialization = falsehibernate.enhancer.enableLazyInitialization = true

    FK references PK of associated entity

    not specifiedIs Owner#lazy initialized by Session#get( Owner.class, id )? false
    Is Owner#lazy a HibernateProxy? true
    LazyToOneOption.FALSE

    Is Owner#lazy initialized by Session#get( Owner.class, id )? true (separate statement)

    Is Owner#lazy a HibernateProxy? false

     

    Improvement: log a warning: <association-path> is mapped as FetchType.LAZY and @LazyToOne(LazyToOneOption.FALSE), which are incompatible. When the owner is loaded, the association will loaded eagerly by a separate query.

    Is Owner#lazy initialized by Session#get( Owner.class, id )? true (separate statement)

    Is Owner#lazy a HibernateProxy? false

     

    Improvement: log a warning: <association-path> is mapped as FetchType.LAZY and @LazyToOne(LazyToOneOption.FALSE), which are incompatible. When the owner is loaded, the association will loaded eagerly by a separate query.

    LazyToOneOption.NO_PROXY

    Is Owner#lazy initialized by Session#get( Owner.class, id )? true

    Is Owner#lazy a HibernateProxy? false


    Improvement: log a warning: <association-path> is mapped as FetchType.LAZY and @LazyToOne(LazyToOneOption.NO_PROXY), but hibernate.enhancer.enableLazyInitialization = false, which is incompatible. hibernate.enhancer.enableLazyInitialization must be true to work with LazyToOneOption.NO_PROXY. When the owner is loaded, the association will loaded eagerly by a separate query.

    Is Owner#lazy initialized by Session#get( Owner.class, id )? false

    Is Owner#lazy a HibernateProxy? false

    LazyToOneOption.PROXYEquivalent @LazyToOne not specified.

    Is Owner#lazy initialized by Session#get( Owner.class, id )? yes

    Is Owner#lazy a HibernateProxy? false


    Improvement: log a warning: <association-path> is mapped as FetchType.LAZY and @LazyToOne(LazyToOneOption.PROXY), but hibernate.enhancer.enableLazyInitialization = true, which is incompatible. hibernate.enhancer.enableLazyInitialization must be false to work with LazyToOneOption.PROXY. When the owner is loaded, the association will loaded eagerly by a separate query.

    FK references non-PK of associated entity

    not specified
    LazyToOneOption.FALSE
    LazyToOneOption.NO_PROXY
    LazyToOneOption.PROXY