[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3810) Transient entities can be inserted twice on merge

Gail Badner (JIRA) noreply at atlassian.com
Tue Mar 10 15:29:38 EDT 2009


Transient entities can be inserted twice on merge
-------------------------------------------------

                 Key: HHH-3810
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3810
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 3.3.1, 3.3.0.GA, 3.2.6
            Reporter: Gail Badner
            Assignee: Gail Badner
             Fix For: 3.2.x, 3.3.x, 3.5


A transient entity being merged can be inserted twice if there is a cascade back to that same entity before it has been saved.

This bug was introduced by the fix for HHH-3229.

This can be illustrated by the following mapping (adapted from the test case at HHH-3046):

Route -- (1 : N) -- Node -- (N : 1) -- Tour            

There are 3 objects:
   route (persistent) 
   pickupNode (transient)
   tour (transient)

Collections are sets.

node.route has cascade="none".
All other associations are cascade="merge,refresh"

route.nodes { pickupNode }
tour.nodes = { pickupNode }

pickupNode.route = route
pickupNode.tour = tour

The following shows the execution path that results in pickupNode being saved twice.

MERGE EVENT route (persistent)

  MERGE EVENT pickupNode (transient)
  |  
  | A) CASCADE_BEFORE_SAVE pickupNode
  |    
  |    MERGE EVENT tour (transient)
  |    | 
  |    | A) CASCADE_BEFORE_SAVE tour (nothing to do)
  |    |
  |    | B) SAVE tour
  |    |
  |    | C) CASCADE_AFTER_SAVE tour
  |    |    
  |    |    MERGE EVENT pickupNode (still transient)
  |    |    | (BUG: embedded merge event for same transient entity!!!)
  |    |    |    
  |    |    | A) CASCADE_BEFORE_SAVE pickupNode
  |    |    |
  |    |    |    MERGE EVENT tour (skip because it is already merged)
  |    |    |
  |    |    | B) SAVE pickupNode 
  |    |    |    (BUG: saved in embedded merge event!!!)
  |    |    |
  |    |    | C) CASCADE_AFTER_SAVE pickupNode
  |    |    |
  |
  | B) SAVE pickupNode
  |    (BUG: saved again in original merge event!!!)
  |
  | C) CASCADE_AFTER_SAVE pickupNode (nothing to do)
  
Prior to applying the fix for HHH-3229, the execution path was:

MERGE EVENT route (persistent)

  MERGE EVENT pickupNode (transient)
  |  
  | A) CASCADE_BEFORE_SAVE pickupNode
  |    
  |    MERGE EVENT tour (transient)
  |    | 
  |    | A) CASCADE_BEFORE_SAVE tour (nothing to do)
  |    |
  |    | B) SAVE tour
  |    |
  |    | C) CASCADE_AFTER_SAVE tour
  |    |    
  |    |    MERGE EVENT pickupNode (still transient; skip because it is already being merged)
  |  
  | B) SAVE pickupNode
  |
  | C) CASCADE_AFTER_SAVE pickupNode (nothing to do)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list