We're updating the issue view to help you get more done. 

Enabling ENABLE_LAZY_LOAD_NO_TRANS results in trying to remove elements in collections

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.

Environment

None

Status

Assignee

Steve Ebersole

Reporter

Andreas Joseph Krogh

Labels

None

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Fix versions

Affects versions

4.1.8
4.1.9

Priority

Blocker