Hibernate Annotations and Lazy Associations for OneToOne and ManyToOne mappings
By default, all Hibernate ToOne assocations are treated as Eager. This is because “Lazy fetching is only conceptually possible for a mandatory association since we have to hit the other table to determine whether the association is null or not!”
When using Hibernate Annotations, the critical bit is optional=”true”
Therefore, you need to map a OneToOne as @OneToOne(fetch=FetchType.LAZY, optional=false) To get lazy loading. The optional part is key, that way Hibernate does not need to check the other side of the association for nulls, since it knows in this case it cannot be a null. So it’s safe to put a proxy there, and proxies are how Hibernate does its lazy loading magic.
The bit that confused me was that if there is a @NotFound(action = NotFoundAction.IGNORE), that will still cause the relation to be EAGER, even if you’ve mapped it as LAZY and optional=false. You must have NotFoundAction.EXCEPTION if you have a NotFoundAction defined at all. This is clear once you think about it (you would be contradicting the optional=false in the ToOne mapping), but it took me a bit to realize this was the case.