EntityKey key = new EntityKey( id, persister, source.getEntityMode() ); Object managedEntity = source.getPersistenceContext().getEntity( key ); entry = source.getPersistenceContext().getEntry( managedEntity ); if ( entry != null ) { // we have specialized case of a detached entity from the // perspective of the merge operation. Specifically, we // have an incoming entity instance which has a corresponding // entry in the current persistence context, but registered // under a different entity instance entityState = DETACHED; }
EntityKey key = new EntityKey( id, this, session.getEntityMode() ); Object entity = session.getPersistenceContext().getEntity( key ); if ( entity != null ) { EntityEntry entry = session.getPersistenceContext().getEntry( entity ); loadedState = entry.getLoadedState(); }
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/event/def/DefaultMergeEventListener.java File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
Method name: void onMerge(MergeEvent, Map) Method name: void delete(Serializable, Object, Object, SessionImplementor)
Number of AST nodes: 5 Number of AST nodes: 5
1
EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
1
EntityKey key = new EntityKey( id, this, session.getEntityMode() );
2
						Object managedEntity = source.getPersistenceContext().getEntity( key );
2
			Object entity = s
3
						entry = source.getPersistenceContext().getEntry( managedEntity );
3
ession.getPersistenceContext().getEntity( key );
4
						if ( entry != null ) {
4
			if ( entity != null ) {
5
							// we have specialized case of a detached entity from the
5
				
6
							// perspective of the merge operation.  Specifically, we
7
							// have an incoming entity instance which has a corresponding
8
							// entry in the current persistence context, but registered
6
EntityEntry entry = session.getPersistenceContext
9
							// under a different entity instance
10
							entityState = DETACHED;
11
			
7
().getEntry( entity );
8
				loadedState = entry.getLoadedState();
12
			}
9
			}
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.2
Clones locationClones are in different classes
Number of node comparisons13
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements2
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)1.5
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                                                                                                    
    5
    EntityKey key = new EntityKey(id, this, session.getEntityMode());
    27
    EntityKey key = new EntityKey(id, persister, source.getEntityMode());
                                                                                                                                              
    28
    Object managedEntity = source.getPersistenceContext().getEntity(key);
    28
    Object managedEntity = source.getPersistenceContext().getEntity(key);
    6
    Object entity = session.getPersistenceContext().getEntity(key);
    Differences
    Expression1Expression2Difference
    managedEntityentityVARIABLE_NAME_MISMATCH
    sourcesessionVARIABLE_NAME_MISMATCH
    org.hibernate.event.EventSourceorg.hibernate.engine.SessionImplementorVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.event.EventSource of variable source does not match with type org.hibernate.engine.SessionImplementor of variable session
    • Make classes org.hibernate.event.EventSource and org.hibernate.engine.SessionImplementor extend a common superclass
    6
    Object entity = session.getPersistenceContext().getEntity(key);
    29
    entry = source.getPersistenceContext().getEntry(managedEntity);
    29
    entry = source.getPersistenceContext().getEntry(managedEntity);
    Preondition Violations
    Unmatched statement entry=source.getPersistenceContext().getEntry(managedEntity); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                      
    30
    if (entry != null)
    30
    if (entry != null)
    7
    if (entity != null)
    Differences
    Expression1Expression2Difference
    entryentityVARIABLE_NAME_MISMATCH
    org.hibernate.engine.EntityEntryjava.lang.ObjectVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Expression entity cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Type org.hibernate.engine.EntityEntry of variable entry does not match with type java.lang.Object of variable entity
    • Make classes org.hibernate.engine.EntityEntry and java.lang.Object extend a common superclass
    7
    if (entity != null)
                                                                                                                                                
    8
    EntityEntry entry = session.getPersistenceContext().getEntry(entity);
                                                                                
    9
    loadedState = entry.getLoadedState();
    31
    entityState = DETACHED;
                                                      
    Precondition Violations (4)
    Row Violation
    1Type org.hibernate.event.EventSource of variable source does not match with type org.hibernate.engine.SessionImplementor of variable session
    2Unmatched statement entry=source.getPersistenceContext().getEntry(managedEntity); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Expression entity cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Type org.hibernate.engine.EntityEntry of variable entry does not match with type java.lang.Object of variable entity