JPA 2.0 / Hibernate: Why does LAZY fetching with “@OneToOne” work out of the box?

后端 未结 2 1267
时光说笑
时光说笑 2021-01-18 05:10

my question is regarding JPA 2.0 with Hibernate, @OneToOne relationships and lazy loading.

First my setup:

  • Spring 3.0.5.RELEASE
  • SprnigData JPA
2条回答
  •  無奈伤痛
    2021-01-18 05:36

    The problem with lazy loading of OneToOne relationship is only on the inverse part of it (the one which is marked with mappedBy attribute). It works fine on the owning side of the relationship. T he difference between those is clear on database level. In your case the question is if the User database table holds an id of AvatarImage as one of the columns or the other way round. If User table has a column with an id of AvatarImage then the lazy loading will work as you said "out-of-box" but it will not work the other way round.

提交回复
热议问题