Uploaded image for project: 'Hibernate ORM'
  1. HHH-11965

Using unproxy in getter does not work properly


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.2.10
    • Fix Version/s: 5.2.12
    • Component/s: hibernate-core
    • Labels:
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Worked in:
    • Last commented by a user?:
    • Sprint:


      Unproxying a lazyly loaded object in a getter method was never a problem up to version 5.1, but in 5.2 Hibernate somehow tries to delete an associated object (OneToOne) from the database although the association was never changed.

      Please have a look at the test case I created, I think this should make it clear: https://github.com/mpe85/hibernate-unproxy-problem (Test class JPAUnitTestCase)

      Relevant code snippet:

      @OneToOne(cascade=CascadeType.ALL, orphanRemoval=true, fetch=FetchType.LAZY)
      public Child getChild() {
      	return (Child) Hibernate.unproxy(child);

      Note: Hibernate.unproxy() was introduced in 5.2, the 5.1 (and prior) code of course looked like this:


      I guess Hibernate expects the getter to return the proxy, but finds the unproxied object and concludes the association was altered (causing the deletion attempt of the child).
      Hibernate should treat the proxy object and the unproxied object as the same object like in 5.1 or earlier so that the unproxying can still be done in the getter (which is very nice because it is a very central place and the caller does not have to care about unproxying).

      Please clarify if this is a bug or if this behaviour was introduced intentionally.


          Issue links



              • Votes:
                0 Vote for this issue
                3 Start watching this issue


                • Created: