Wednesday, November 12, 2008

Nullable Bi-directional One-to-One associations cannot be lazy loaded in Hibernate

If you have a Bi-Directional One-to-One association that is nullable - beware!

It cannot be lazily-loaded by definition, as explained in this confusing and poorly worded explanation.

Normally this is not a problem, Hibernate will just ignore your lazy loading annotation or xml definition. However I have encountered a situation where labelling this kind of assocation with lazy load causes Hibernate to enter an infinite loop.

So beware!