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.get( Parent.class, "p1" ); assertEquals( 1, parent.getChildren().size() ); session.getTransaction().commit(); session.close(); assertEquals( 1, parent.getChildren().size() ); assertEquals( recreateCount, stats.getRecreateCount() ); assertEquals( updateCount, stats.getUpdateCount() ); session = openSession(); session.beginTransaction(); 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 testCollectiondirtyChecking() 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.get( Parent.class, "p1" );
16
		container = ( Container ) session.merge( 
17
		assertEquals( 1, parent.getChildren().size() );
17
container );
18
		session.getTransaction().commit();
18
		session.getTransaction().commit();
19
		session.close();
19
		session.close();
20
		assertEquals( 1, parent.getChildren().size() );
20
		assertEquals( 1, container.getContents().size() );
21
		assertEquals( recreateCount, stats.getRecreateCount() );
21
		assertEquals( recreateCount, stats.getRecreateCount() );
22
		assertEquals( updateCount, stats.getUpdateCount() );
22
		assertEquals( updateCount, stats.getUpdateCount() );
23
		session = openSession();
23
		session = openSession();
24
		session.beginTransaction();
24
		session.beginTransaction();
25
		assertEquals( 1, parent.getChildren
25
		container = ( Container ) session.get( Container.class, container.getId() );
26
().size() );
26
		assertEquals( 1, container.getContents().size() );
27
		session.delete( parent );
27
		session.delete( container );
28
		session.getTransaction().commit();
28
		session.getTransaction().commit();
29
		session.close();
29
		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 statements19
    Number of unmapped statements in the first code fragment8
    Number of unmapped statements in the second code fragment8
    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");
    Preondition Violations
    Unmatched statement Container container=new Container("p1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3
    Container container = new Container("p1");
    3
    Parent parent = new Parent("p1");
    3
    Parent parent = new Parent("p1");
    Preondition Violations
    Unmatched statement Parent parent=new Parent("p1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                        
                                                                                                            
    4
    Container.Content c1 = new Container.Content("c1");
    Preondition Violations
    Unmatched statement Container.Content c1=new Container.Content("c1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4
    Container.Content c1 = new Container.Content("c1");
    4
    Child child = new Child("c1");
    4
    Child child = new Child("c1");
    Preondition Violations
    Unmatched statement Child child=new Child("c1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                  
                                                                          
    5
    container.getContents().add(c1);
    5
    parent.getChildren().add(child);
                                                                          
    6
    child.setParent(parent);
    6
    child.setParent(parent);
    Preondition Violations
    Unmatched statement child.setParent(parent); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                          
    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
    Parent.classContainer.classLITERAL_VALUE_MISMATCH
    ".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();
                                                                                
    12
    container.setName("another name");
    Preondition Violations
    Unmatched statement container.setName("another name"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    12
    container.setName("another name");
    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.get(Parent.class, "p1");
    15
    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
                                                                                                        
    16
    assertEquals(1, parent.getChildren().size());
                                                                                                    
    17
    session.getTransaction().commit();
    16
    session.getTransaction().commit();
    18
    session.close();
    17
    session.close();
                                                                                                          
    18
    assertEquals(1, container.getContents().size());
    19
    assertEquals(1, parent.getChildren().size());
                                                                                                    
    20
    assertEquals(recreateCount, stats.getRecreateCount());
    19
    assertEquals(recreateCount, stats.getRecreateCount());
    21
    assertEquals(updateCount, stats.getUpdateCount());
    20
    assertEquals(updateCount, stats.getUpdateCount());
    22
    session = openSession();
    21
    session = openSession();
    23
    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());
                                                                                                          
    24
    assertEquals(1, container.getContents().size());
    24
    assertEquals(1, parent.getChildren().size());
                                                                                                    
    25
    session.delete(parent);
    25
    session.delete(parent);
    25
    session.delete(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
    25
    session.delete(container);
    26
    session.getTransaction().commit();
    26
    session.getTransaction().commit();
    27
    session.close();
    27
    session.close();
    Precondition Violations (11)
    Row Violation
    1Unmatched statement Container container=new Container("p1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement Parent parent=new Parent("p1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement Container.Content c1=new Container.Content("c1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Unmatched statement Child child=new Child("c1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    5Unmatched statement child.setParent(parent); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    6Type org.hibernate.test.collection.set.Parent of variable parent does not match with type org.hibernate.test.collection.set.Container of variable container
    7Unmatched statement container.setName("another name"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    8Unmatched 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
    9Unmatched 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
    10Unmatched 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
    11Type org.hibernate.test.collection.set.Parent of variable parent does not match with type org.hibernate.test.collection.set.Container of variable container