When using bytecode enhancement and @OneToOne with @LazyToOne(value = LazyToOneOption.NO_PROXY) the lazily initialized entities are not tracked properly when the setter for the entity is called before the getter for that entity. In the attached test case, hibernate does not delete the old attached entity, while still persisting the new entity. This causes errors the next time we try to load the owning entity, because the OneToOne relationship now has two owned entities. If the getter is called before the setter is called, hibernate does delete the old entity. Test case: https://github.com/chouze/hibernate-test-case-templates/tree/no_proxy_tracking |