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

Join table of lazy loading many-to-many relation not saved when lazy initialization bytecode enhancement is active

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

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

      Description

      Adding items to a lazy loading many-to-many Set (and saving the entity) doesn't trigger the appropriate INSERT SQL query, so the new relations are not saved, when the parent entity has an @ElementCollection field too.

      A self-contained demo is available in HHH-10865.zip, it's runnable with mvn clean test.

      I've experienced this issue both with Hibernate ORM 5.1.0 and 5.2.0; but 5.0.9 seems to be working fine.

      I've found that any of the following changes make it work again (see the demo app):

      • Uncomment the parent.getNames(); command at Main.java:75.
      • Remove the names field, and the getNames() and setNames(Set<String>) methods of the Parent entity.
      • Change the fetch attribute of the @ManyToMany annotation to FetchType.EAGER.
      • Set enableLazyInitialization to false in pom.xml.
      • Change Hibernate's version to 5.0.9 in pom.xml (there are two instances).

      Performing any of these changes makes the insert into parents_children (parent, child) values (?, ?) SQL command appear in the standard output.

        Attachments

        1. HHH-10865.zip
          5 kB
        2. HHH-10865-2.diff
          1 kB
        3. HHH-10865-3.diff
          1 kB

          Issue links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: