Fixed
Details
Assignee
Former userFormer user(Deactivated)Reporter
Former userFormer user(Deactivated)Components
Fix versions
Priority
Major
Details
Details
Assignee
Former user
Former user(Deactivated)Reporter
Former user
Former user(Deactivated)Components
Fix versions
Priority
Created August 12, 2010 at 7:50 PM
Updated February 9, 2012 at 6:21 AM
Resolved January 20, 2012 at 1:59 AM
The proposed fix will have no affect on the cascade algorithm itself. IOW, EntityInsertAction and EntityIdentityInsertAction objects will be added to the ActionQueue in the same order as before.
Preposed algorithm:
1) When an EntityInsertAction or EntityIdentityInsertAction object is added to the ActonQueue,find any transient entities that would cause the insert to fail;
2) If the entity insert action would fail due to non-nullable transient entities, then that action is added to ActionQueue as an "unresolved" insert action.
3) Otherwise, execute ActionQueue.addResolvedEntityInsertAction( insert ) which:
3a) the action is processed (i.e., added to ActionQueue.insertions or executed);
3b) the entity status is changed to Status.MANAGED;
3c) resolve dependencies that "unresolved" insert actions have on the entity;
3d) if any "unresolved" insert actions no longer have any non-nullable transient entity dependencies, then process as a "resolved" insert action by executing 3).
4) If ActionQueue still has unresolved entity insert actions when the operation completes, then TransientObjectException is thrown.
This model (used by org.hibernate.test.annotations.cascade.multicircle tests) illustrates the proposed fix:
In the diagram:
all associations are bidirectional.
assocations marked with '*' cascade persist, save, merge operations to the associated entities
(e.g., B cascades persist to D, but D does not cascade persist to B)
If b, c, d, e, f, and g are all transient unsaved that are associated with each other, then when Session.persist( b ) is called, then entities are added to the ActionQueue in the following order:
c, d (depends on e), f (depends on d, g), e, b, g
Before the fix, entities would be inserted in the same order they were added to the ActionQueue, resulting in an exception when saving d (because d.e is non-nullable and transient)
Using the proposed fix, entities will be successfully inserted in the following order:
c, e, d, b, g, f
In this case, inserting d is delayed until after e is inserted, and inserting f is delayed until after e and g are inserted.