As you know, lazy loading of inverse (not owning) optional one-to-one relationships using Hibernate does not work out of the box.
Hibernate does not know if a proxy object or NULL must be used, so the loading occurs before the field is accessed for the first time (NOT LAZY).
There are some solutions for this problem (also known as shared PK one-to-zero-or-one), and I need to use the one that involves runtime bytecode instrumentation. It requires Hibernate as JPA provider in full-blown JEE environment (I am using JBoss 7.1.1), setting "hibernate.ejb.use_class_enhancer" to true.
The application works fine (no errors), BUT nothing changes (Hibernate still runs thousands of queries). My goal is to load the optional onetoone relationship only when the value is needed, because the eager loading is giving me performance issues.