[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5472) Delay saving an entity if it does not cascade the save to non-nullable transient entities
Steve Ebersole (JIRA)
noreply at atlassian.com
Wed Jan 11 13:05:13 EST 2012
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5472?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45091#comment-45091 ]
Steve Ebersole commented on HHH-5472:
-------------------------------------
Lets do this in 4.1 then for the reasons I stated on the pull request
> Delay saving an entity if it does not cascade the save to non-nullable transient entities
> ------------------------------------------------------------------------------------------
>
> Key: HHH-5472
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5472
> Project: Hibernate Core
> Issue Type: Improvement
> Components: core
> Reporter: Gail Badner
> Assignee: Gail Badner
> Fix For: 4.0.1
>
>
> 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:
> {noformat}
> ------------------------------ N G
> |
> | 1
> | |
> | |
> | N
> |
> | E N--------------0,1 * F
> |
> | 1 N
> | | |
> | | |
> 1 N |
> * |
> B * N---1 D * 1------------------
> *
> N N
> | |
> | |
> 1 |
> |
> C * 1-----
> {noformat}
> 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.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list