Persistent immutable and read-only entities are updated before being deleted

Description

Read-only and immutable entities that are in persistent state when deleted are updated before being deleted. Read-only and immutable entities that are detached when deleted are not updated before being deleted.

In the following examples, Contract is an immutable class.

Example 1: Immutable entity is updated with the same property values as just read

s = openSession();
t = s.beginTransaction();
c = (Contract) s.get( Contract.class, c.getId() );
s.delete(c);
t.commit();
s.close();

Hibernate: update Contract set customerName=?, type=? where id=?
17:59:32,640 TRACE StringType:151 - binding 'gavin' to parameter: 1
17:59:32,640 TRACE StringType:151 - binding 'phone' to parameter: 2
17:59:32,641 TRACE LongType:151 - binding '1' to parameter: 3

... (immutable collection, Contract.getVariations() is also updated and deleted)

Hibernate: delete from Contract where id=?
17:59:32,654 TRACE LongType:151 - binding '1' to parameter: 1

-------------------------------------------------------------------------
Example 2: Immutable entity is updated with a new property value before being deleted

s = openSession();
t = s.beginTransaction();
c = (Contract) s.get( Contract.class, c.getId() );
c.setCustomerName( "Sherman" );
s.delete(c);
t.commit();
s.close();

Hibernate: update Contract set customerName=?, type=? where id=?
17:59:33,221 TRACE StringType:151 - binding 'Sherman' to parameter: 1
17:59:33,221 TRACE StringType:151 - binding 'phone' to parameter: 2
17:59:33,222 TRACE LongType:151 - binding '6' to parameter: 3
... (immutable collection, Contract.getVariations() is also updated and deleted)
Hibernate: delete from Contract where id=?
17:59:33,242 TRACE LongType:151 - binding '6' to parameter: 1

Example 3: No update when the immutable entity is detached when it is deleted.

s = openSession();
t = s.beginTransaction();
s.delete( c );
t.commit();
s.close();

... (immutable collection, Contract.getVariations() is deleted)
Hibernate: delete from Contract where id=?
17:59:33,337 TRACE LongType:151 - binding '8' to parameter: 1

Environment

None

Activity

Show:
Gail Badner
February 24, 2010, 12:22 AM

Fixed in trunk.

Now updates before deleting immutable and read-only entities only nullify references to transient entities (which is necessary to avoid constraint violations). No other columns are affected by these updates.

Steve Ebersole
March 21, 2011, 7:08 PM

Bulk closing stale resolved issues

Fixed

Assignee

Gail Badner

Reporter

Gail Badner

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure