Hibernate: one-to-one lazy loading, optional = false

If the association is optional, Hibernate has no way of knowing if an address exists for a given person without issuing a query. So it can’t populate the address field with a proxy, because there could be no address referencing the person, and it can’t populate it with null, because there might be an address referencing the person.

When you make the association mandatory (i.e. optional=false), it trusts you and assumes that an address exists, since the association is mandatory. So it directly populates the address field with a proxy, knowing that there is an address referencing the person.

Leave a Comment