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

Accessing a lazy collection in an enhanced class deletes it afterwards

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects versions: None
    • Fix versions: 5.0.10, 5.2.0, 5.1.1
    • Components: hibernate-core
    • Labels:
      None
    • Environment:
      Hibernate 5.1.0
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      I'm trying to migrate from 4.3 to 5.1 using the new bytecode enhancer.

      Given a class Foo with a collection of Bars with orphanRemoval=true, even just accessing the collection results in an exception:

      A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: org.hibernate.test.bytecodeissue.Foo.bar

      See attached test case.

      The second test case shows the issue without orphanRemoval in an enhanced class: Bar has a @ManyToMany annotated Set of Foos that are lazy loaded. The test case shows the following output:

      (...)
      Hibernate: /* insert org.hibernate.test.hhh10708_bytecodeissue_wo_orphanremoval.Bar2 */ insert into Bar2 (id) values (?)
      Hibernate: /* insert org.hibernate.test.hhh10708_bytecodeissue_wo_orphanremoval.Foo2 */ insert into Foo2 (id) values (?)
      Hibernate: /* insert org.hibernate.test.hhh10708_bytecodeissue_wo_orphanremoval.Foo2 */ insert into Foo2 (id) values (?)
      Hibernate: /* insert collection row org.hibernate.test.hhh10708_bytecodeissue_wo_orphanremoval.Bar2.foos */ insert into Bar2_Foo2 (Bar2_id, foos_id) values (?, ?)
      Hibernate: /* insert collection row org.hibernate.test.hhh10708_bytecodeissue_wo_orphanremoval.Bar2.foos */ insert into Bar2_Foo2 (Bar2_id, foos_id) values (?, ?)
      Hibernate: /* load org.hibernate.test.hhh10708_bytecodeissue_wo_orphanremoval.Bar2 */ select bar2x0_.id as id1_0_0_ from Bar2 bar2x0_ where bar2x0_.id=?
      Hibernate: select foos0_.Bar2_id as Bar1_1_0_, foos0_.foos_id as foos_id2_1_0_, foo2x1_.id as id1_2_1_ from Bar2_Foo2 foos0_ inner join Foo2 foo2x1_ on foos0_.foos_id=foo2x1_.id where foos0_.Bar2_id=?
      2016-04-26 14:57:05,875 ERROR [Time-limited test] (TestCase2.java:81) collection = [org.hibernate.test.hhh10708_bytecodeissue_wo_orphanremoval.Foo2@7de4e70d, org.hibernate.test.hhh10708_bytecodeissue_wo_orphanremoval.Foo2@5ed545b9]
      Hibernate: /* delete collection org.hibernate.test.hhh10708_bytecodeissue_wo_orphanremoval.Bar2.foos */ delete from Bar2_Foo2 where Bar2_id=?
      2016-04-26 14:57:05,882 ERROR [Time-limited test] (TestCase2.java:83) DONE!
      (...)
      

      The collection is deleted after it was accessed in the log error statement.

      The cases works fine in test case when I set doDirtyCheckingInline to false in the EnhancementTask - but in our live environment with far more complex classes, I can achieve the same behaviour with disabled doDirtyCheckingInline.

      Everything works fine without bytecode enhancement.

        Attachments

        1. Bar.java
          0.7 kB
        2. Bar2.java
          0.7 kB
        3. bytecode_enhancement.xml
          0.9 kB
        4. Foo.java
          0.7 kB
        5. Foo2.java
          0.3 kB
        6. TestCase.java
          3 kB
        7. TestCase2.java
          3 kB

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - Not Specified
                Not Specified
                Logged:
                Time Spent - 12h 14m
                12h 14m