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

Enabling ENABLE_LAZY_LOAD_NO_TRANS results in trying to remove elements in collections

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 4.1.8, 4.1.9
    • Component/s: None
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true

      Description

      This worked fine in Hibernate-4.1.7 but stopped working in 4.1.8

      Iterating over a collection in an Entity outside the transaction (persistence-context) makes org.hibernate.engine.internal.Collections.prepareCollectionForUpdate() think that ownerChanged == true, which results in:

      // Collections:252 in Hibernate-4.1.9.Final
      entry.setDoremove( true );

      This means that Hibernate will silently clear collections and remove data if you access a collection outside the transaction with ENABLE_LAZY_LOAD_NO_TRANS enabled.

      As if this is not bad enough, if you have a constraint in the DB preventing this delete, then this results in Hibernate leaking connections because ( ( Session) session ).getTransaction().commit() in AbstractPersistentCollection:241 throws an Exception, resulting in the connection not being closed on line 243.

        Attachments

          Activity

            People

            • Votes:
              16 Vote for this issue
              Watchers:
              18 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: