Session s = openSession(); s.beginTransaction(); A a = new A(); a.setData( "Anna" ); s.save( a ); s.getTransaction().commit(); s.close(); // modify detached entity modifyEntity( a ); s = openSession(); s.beginTransaction(); a = ( A ) s.merge( a ); s.getTransaction().commit(); s.close(); verifyModifications( a.getId() );
Session s = openSession(); s.beginTransaction(); Item item = new Item(); item.setName( "dummy" ); s.persist( item ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); s.delete( item ); boolean contains = s.contains( item ); s.getTransaction().commit(); s.close(); assertFalse( "expecting removed entity to not be contained", contains );
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/cascade/MultiPathCascadeTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/jpa/removed/RemovedEntityTest.java
Method name: void testMultiPathMergeModifiedDetached() Method name: void testRemoveThenContains()
Number of AST nodes: 14 Number of AST nodes: 14
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		s.beginTransaction();
3
		A a = new A();
3
		Item item = new Item();
4
		a.setData( "Anna" );
4
		item.setName( "dummy" );
5
		s.save( a );
5
		s.persist( item );
6
		s.getTransaction().commit();
6
		s.getTransaction().commit();
7
		s.close();
7
		s.close();
8
		// modify detached entity
9
		modifyEntity( a );
8

10
		s = openSession();
9
		s = openSession();
11
		s.beginTransaction();
10
		s.beginTransaction();
12
		a = ( A ) s.merge( a
11
		s.delete( item );
13
 );
12
		boolean contains = s.contains( item );
14
		s.getTransaction().commit();
13
		s.getTransaction().commit();
15
		s.close();
14
		s.close();
16
		verifyModifications( a.getId()
17
 );
15
		assertFalse( "expecting removed entity to not be contained", contains );
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.0
Clones locationClones are in different classes having the same super class
Number of node comparisons76
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements9
    Number of unmapped statements in the first code fragment5
    Number of unmapped statements in the second code fragment5
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
    2
    s.beginTransaction();
    2
    s.beginTransaction();
                                                    
    3
    Item item = new Item();
    3
    A a = new A();
    3
    A a = new A();
    Preondition Violations
    Unmatched statement A a=new A(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                  
                                                      
    4
    item.setName("dummy");
    Preondition Violations
    Unmatched statement item.setName("dummy"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4
    item.setName("dummy");
    4
    a.setData("Anna");
    4
    a.setData("Anna");
    Preondition Violations
    Unmatched statement a.setData("Anna"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                              
                                          
    5
    s.persist(item);
    Preondition Violations
    Unmatched statement s.persist(item); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5
    s.persist(item);
    5
    s.save(a);
    5
    s.save(a);
    Preondition Violations
    Unmatched statement s.save(a); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                              
    6
    s.getTransaction().commit();
    6
    s.getTransaction().commit();
    7
    s.close();
    7
    s.close();
    8
    modifyEntity(a);
    8
    modifyEntity(a);
    14
    assertFalse("expecting removed entity to not be contained", contains);
    Differences
    Expression1Expression2Difference
    modifyEntityassertFalseMETHOD_INVOCATION_NAME_MISMATCH
    modifyEntity(a)assertFalse("expecting removed entity to not be contained",contains)TYPE_COMPATIBLE_REPLACEMENT
    modifyEntity(a)assertFalse("expecting removed entity to not be contained",contains)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method modifyEntity
    Expression assertFalse("expecting removed entity to not be contained",contains) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    Expression assertFalse("expecting removed entity to not be contained",contains) is a void method call, and thus it cannot be parameterized
    Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method modifyEntity
    Expression assertFalse("expecting removed entity to not be contained",contains) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    Expression assertFalse("expecting removed entity to not be contained",contains) is a void method call, and thus it cannot be parameterized
    14
    assertFalse("expecting removed entity to not be contained", contains);
    9
    s = openSession();
    8
    s = openSession();
    10
    s.beginTransaction();
    9
    s.beginTransaction();
                                          
    10
    s.delete(item);
    Preondition Violations
    Unmatched statement s.delete(item); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10
    s.delete(item);
                                                                                
    11
    boolean contains = s.contains(item);
    Preondition Violations
    Unmatched statement boolean contains=s.contains(item); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11
    boolean contains = s.contains(item);
    11
    a = (A)s.merge(a);
    11
    a = (A)s.merge(a);
    Preondition Violations
    Unmatched statement a=(A)s.merge(a); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                            
    12
    s.getTransaction().commit();
    12
    s.getTransaction().commit();
    13
    s.close();
    13
    s.close();
    14
    verifyModifications(a.getId());
                                                                          
    Precondition Violations (16)
    Row Violation
    1Unmatched statement A a=new A(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement item.setName("dummy"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement a.setData("Anna"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Unmatched statement s.persist(item); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement s.save(a); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression assertFalse("expecting removed entity to not be contained",contains) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    9Expression assertFalse("expecting removed entity to not be contained",contains) is a void method call, and thus it cannot be parameterized
    10Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression assertFalse("expecting removed entity to not be contained",contains) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    13Expression assertFalse("expecting removed entity to not be contained",contains) is a void method call, and thus it cannot be parameterized
    14Unmatched statement s.delete(item); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15Unmatched statement boolean contains=s.contains(item); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16Unmatched statement a=(A)s.merge(a); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted