Additional queries in JPA

后端 未结 2 446
悲&欢浪女
悲&欢浪女 2021-01-24 05:11

I have two classes InvitedPerson and Flight with a one to one relationship with each other. Here is how they are annotated.

public clas         


        
2条回答
  •  旧时难觅i
    2021-01-24 05:59

    I believe this is due to one of Hibernate's idiosyncrasies:

    non-optional one-to-one relationships are eagerly loaded regardless of whether they are mapped as Lazy.

    The reasoning behind this is that as the engine has to look in the association table anyway - to determine whether it should set the association as a proxy or as null - then it may as well load the associated entity anyway.

    I have experienced this myself and as far as I know the only way round it is to mark the relationship with optional=false which tells Hibernate it can always set a proxy.

    If the relationship is optional then the only other option seems to be byte code instrumentation.

    See also:

    https://community.jboss.org/wiki/SomeExplanationsOnLazyLoadingone-to-one

    Making a OneToOne-relation lazy

提交回复
热议问题