Session session = openSession(); session.beginTransaction(); Parent parent = new Parent( "p1" ); Child child = new Child( "c1" ); parent.getChildren().add( child ); child.setParent( parent ); session.save( parent ); session.getTransaction().commit(); session.close(); CollectionStatistics stats = sfi().getStatistics().getCollectionStatistics( Parent.class.getName() + ".children" ); long recreateCount = stats.getRecreateCount(); long updateCount = stats.getUpdateCount(); session = openSession(); session.beginTransaction(); parent = ( Parent ) session.merge( parent ); session.getTransaction().commit(); session.close(); assertEquals( 1, parent.getChildren().size() ); assertEquals( recreateCount, stats.getRecreateCount() ); assertEquals( updateCount, stats.getUpdateCount() ); session = openSession(); session.beginTransaction(); parent = ( Parent ) session.get( Parent.class, "p1" ); assertEquals( 1, parent.getChildren().size() ); session.delete( parent ); session.getTransaction().commit(); session.close();
Session session = openSession(); session.beginTransaction(); Container container = new Container( "p1" ); Container.Content c1 = new Container.Content( "c1" ); container.getContents().add( c1 ); session.save( container ); session.getTransaction().commit(); session.close(); CollectionStatistics stats = sfi().getStatistics().getCollectionStatistics( Container.class.getName() + ".contents" ); long recreateCount = stats.getRecreateCount(); long updateCount = stats.getUpdateCount(); container.setName( "another name" ); session = openSession(); session.beginTransaction(); container = ( Container ) session.merge( container ); session.getTransaction().commit(); session.close(); assertEquals( 1, container.getContents().size() ); assertEquals( recreateCount, stats.getRecreateCount() ); assertEquals( updateCount, stats.getUpdateCount() ); session = openSession(); session.beginTransaction(); container = ( Container ) session.get( Container.class, container.getId() ); assertEquals( 1, container.getContents().size() ); session.delete( container ); session.getTransaction().commit(); session.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java
Method name: void testCollectionMerging() Method name: void testCompositeElementMergingFailureExpected()
Number of AST nodes: 27 Number of AST nodes: 27
1
Session session = openSession();
1
Session session = openSession();
2
		session.beginTransaction();
2
		session.beginTransaction();
3
		Parent parent = new Parent( "p1" );
3
		
4
		Child child = new Child( "c1" );
5
		parent.getChildren().add( child );
6
		child.setParent( parent
4
Container container = new Container( "p1" );
5
		Container.Content c1 = new Container.Content( "c1" );
7
 );
6
		container.getContents().add( c1 );
8
		session.save( parent );
7
		session.save( container );
9
		session.getTransaction().commit();
8
		session.getTransaction().commit();
10
		session.close();
9
		session.close();
11
		CollectionStatistics stats =  sfi().getStatistics().getCollectionStatistics( Parent.class.getName() + ".children" );
10
		CollectionStatistics stats =  sfi().getStatistics().getCollectionStatistics( Container.class.getName() + ".contents" );
12
		long recreateCount = stats.getRecreateCount();
11
		long recreateCount = stats.getRecreateCount();
13
		long updateCount = stats.getUpdateCount();
12
		long updateCount = stats.getUpdateCount();
13
		container.setName( "another name" );
14
		session = openSession();
14
		session = openSession();
15
		session.beginTransaction();
15
		session.beginTransaction();
16
		parent = ( Parent ) session.merge( parent );
16
		container = ( Container ) session.merge( container );
17
		session.getTransaction().commit();
17
		session.getTransaction().commit();
18
		session.close();
18
		session.close();
19
		assertEquals( 1, parent.getChildren().size() );
19
		assertEquals( 1, container.getContents().size() );
20
		assertEquals( recreateCount, stats.getRecreateCount() );
20
		assertEquals( recreateCount, stats.getRecreateCount() );
21
		assertEquals( updateCount, stats.getUpdateCount() );
21
		assertEquals( updateCount, stats.getUpdateCount() );
22
		session = openSession();
22
		session = openSession();
23
		session.beginTransaction();
23
		session.beginTransaction();
24
		parent = ( Parent ) session.get( Parent.class, "p1" );
24
		container = ( Container ) session.get( Container.class, container.getId() );
25
		assertEquals( 1, parent.getChildren().size() );
25
		assertEquals( 1, container.getContents().size() );
26
		session.delete( parent );
26
		session.delete( container );
27
		session.getTransaction().commit();
27
		session.getTransaction().commit();
28
		session.close();
28
		session.close();
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 declared in the same class
Number of node comparisons287
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements22
    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 session = openSession();
    1
    Session session = openSession();
    2
    session.beginTransaction();
    2
    session.beginTransaction();
                                                                                          
    3
    Container container = new Container("p1");
    3
    Parent parent = new Parent("p1");
                                                                        
                                                                                                            
    4
    Container.Content c1 = new Container.Content("c1");
    4
    Child child = new Child("c1");
                                                                  
                                                                          
    5
    container.getContents().add(c1);
    5
    parent.getChildren().add(child);
                                                                          
    6
    child.setParent(parent);
    6
    child.setParent(parent);
    18
    assertEquals(1, container.getContents().size());
    Differences
    Expression1Expression2Difference
    setParentassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    child.setParent(parent)assertEquals(1,container.getContents().size())ARGUMENT_NUMBER_MISMATCH
    childMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression child.setParent(parent) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,container.getContents().size()) is a void method call, and thus it cannot be parameterized
    Expression child.setParent(parent) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,container.getContents().size()) is a void method call, and thus it cannot be parameterized
    18
    assertEquals(1, container.getContents().size());
    7
    session.save(parent);
    7
    session.save(parent);
    6
    session.save(container);
    Differences
    Expression1Expression2Difference
    parentcontainerVARIABLE_NAME_MISMATCH
    org.hibernate.test.collection.set.Parentorg.hibernate.test.collection.set.ContainerVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.collection.set.Parent of variable parent does not match with type org.hibernate.test.collection.set.Container of variable container
    • Make classes org.hibernate.test.collection.set.Parent and org.hibernate.test.collection.set.Container extend a common superclass
    6
    session.save(container);
    8
    session.getTransaction().commit();
    7
    session.getTransaction().commit();
    9
    session.close();
    8
    session.close();
    10
    CollectionStatistics stats = sfi().getStatistics().getCollectionStatistics(Parent.class.getName() + ".children");
    10
    CollectionStatistics stats = sfi().getStatistics().getCollectionStatistics(Parent.class.getName() + ".children");
    9
    CollectionStatistics stats = sfi().getStatistics().getCollectionStatistics(Container.class.getName() + ".contents");
    Differences
    Expression1Expression2Difference
    ".children"".contents"LITERAL_VALUE_MISMATCH
    9
    CollectionStatistics stats = sfi().getStatistics().getCollectionStatistics(Container.class.getName() + ".contents");
    11
    long recreateCount = stats.getRecreateCount();
    10
    long recreateCount = stats.getRecreateCount();
    12
    long updateCount = stats.getUpdateCount();
    11
    long updateCount = stats.getUpdateCount();
    13
    session = openSession();
    13
    session = openSession();
    14
    session.beginTransaction();
    14
    session.beginTransaction();
                                                                                                        
    15
    container = (Container)session.merge(container);
    Preondition Violations
    Unmatched statement container=(Container)session.merge(container); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15
    container = (Container)session.merge(container);
    15
    parent = (Parent)session.merge(parent);
    15
    parent = (Parent)session.merge(parent);
    Preondition Violations
    Unmatched statement parent=(Parent)session.merge(parent); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                      
    16
    session.getTransaction().commit();
    16
    session.getTransaction().commit();
    17
    session.close();
    17
    session.close();
    18
    assertEquals(1, parent.getChildren().size());
    18
    assertEquals(1, parent.getChildren().size());
    12
    container.setName("another name");
    Differences
    Expression1Expression2Difference
    assertEqualssetNameMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,parent.getChildren().size())container.setName("another name")ARGUMENT_NUMBER_MISMATCH
    containerMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    Expression container.setName("another name") is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    Expression container.setName("another name") is a void method call, and thus it cannot be parameterized
    12
    container.setName("another name");
    19
    assertEquals(recreateCount, stats.getRecreateCount());
    19
    assertEquals(recreateCount, stats.getRecreateCount());
    20
    assertEquals(updateCount, stats.getUpdateCount());
    20
    assertEquals(updateCount, stats.getUpdateCount());
    21
    session = openSession();
    21
    session = openSession();
    22
    session.beginTransaction();
    22
    session.beginTransaction();
                                                                                                                                                    
    23
    container = (Container)session.get(Container.class, container.getId());
    Preondition Violations
    Unmatched statement container=(Container)session.get(Container.class,container.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    23
    container = (Container)session.get(Container.class, container.getId());
    23
    parent = (Parent)session.get(Parent.class, "p1");
    23
    parent = (Parent)session.get(Parent.class, "p1");
    Preondition Violations
    Unmatched statement parent=(Parent)session.get(Parent.class,"p1"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                        
    24
    assertEquals(1, parent.getChildren().size());
    24
    assertEquals(1, parent.getChildren().size());
    25
    session.delete(container);
    Differences
    Expression1Expression2Difference
    assertEqualsdeleteMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,parent.getChildren().size())session.delete(container)ARGUMENT_NUMBER_MISMATCH
    sessionMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression session.delete(container) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    Expression session.delete(container) is a void method call, and thus it cannot be parameterized
    Expression session.delete(container) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    Expression session.delete(container) is a void method call, and thus it cannot be parameterized
    25
    session.delete(container);
    25
    session.delete(parent);
    25
    session.delete(parent);
    24
    assertEquals(1, container.getContents().size());
    Differences
    Expression1Expression2Difference
    deleteassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    session.delete(parent)assertEquals(1,container.getContents().size())ARGUMENT_NUMBER_MISMATCH
    sessionMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression session.delete(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.delete(parent) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,container.getContents().size()) is a void method call, and thus it cannot be parameterized
    Expression session.delete(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.delete(parent) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,container.getContents().size()) is a void method call, and thus it cannot be parameterized
    24
    assertEquals(1, container.getContents().size());
    26
    session.getTransaction().commit();
    26
    session.getTransaction().commit();
    27
    session.close();
    27
    session.close();
    Precondition Violations (25)
    Row Violation
    1Expression child.setParent(parent) is a void method call, and thus it cannot be parameterized
    2Expression assertEquals(1,container.getContents().size()) is a void method call, and thus it cannot be parameterized
    3Expression child.setParent(parent) is a void method call, and thus it cannot be parameterized
    4Expression assertEquals(1,container.getContents().size()) is a void method call, and thus it cannot be parameterized
    5Type org.hibernate.test.collection.set.Parent of variable parent does not match with type org.hibernate.test.collection.set.Container of variable container
    6Unmatched statement container=(Container)session.merge(container); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched statement parent=(Parent)session.merge(parent); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    9Expression container.setName("another name") is a void method call, and thus it cannot be parameterized
    10Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    11Expression container.setName("another name") is a void method call, and thus it cannot be parameterized
    12Unmatched statement container=(Container)session.get(Container.class,container.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Unmatched statement parent=(Parent)session.get(Parent.class,"p1"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14Expression session.delete(container) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    16Expression session.delete(container) is a void method call, and thus it cannot be parameterized
    17Expression session.delete(container) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    19Expression session.delete(container) is a void method call, and thus it cannot be parameterized
    20Expression session.delete(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21Expression session.delete(parent) is a void method call, and thus it cannot be parameterized
    22Expression assertEquals(1,container.getContents().size()) is a void method call, and thus it cannot be parameterized
    23Expression session.delete(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    24Expression session.delete(parent) is a void method call, and thus it cannot be parameterized
    25Expression assertEquals(1,container.getContents().size()) is a void method call, and thus it cannot be parameterized