Session s = openSession(); Baz baz = new Baz(); Collection fooBag = new ArrayList(); fooBag.add( new Foo() ); fooBag.add( new Foo() ); baz.setFooBag(fooBag); s.save(baz); s.flush(); fooBag = baz.getFooBag(); s.find("from Baz baz left join fetch baz.fooBag"); assertTrue( fooBag==baz.getFooBag() ); s.connection().commit(); s.close(); s = openSession(); baz = (Baz) s.load( Baz.class, baz.getCode() ); Object bag = baz.getFooBag(); assertFalse( Hibernate.isInitialized(bag) ); s.find("from Baz baz left join fetch baz.fooBag"); assertTrue( bag==baz.getFooBag() ); assertTrue( baz.getFooBag().size()==2 ); s.delete(baz); s.flush(); s.connection().commit(); s.close();
Session s = openSession(); Category c = new Category(); List list = new ArrayList(); c.setSubcategories(list); list.add( new Category() ); c.setName("root"); Serializable id = s.save(c); s.flush(); s.connection().commit(); s.close(); s = openSession(); c = (Category) s.load(Category.class, id); s.refresh(c); s.flush(); assertTrue( c.getSubcategories().size()==1 ); s.flush(); s.connection().commit(); s.close(); s = openSession(); c = (Category) s.load(Category.class, id); assertTrue( c.getSubcategories().size()==1 ); s.delete(c); s.flush(); s.connection().commit(); s.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java
Method name: void testFetchInitializedCollection() Method name: void testCollectionRefresh()
Number of AST nodes: 24 Number of AST nodes: 25
1
Session s = openSession();
1
Session s = openSession();
2
		Baz baz = new Baz();
2
		
3
		Collection fooBag = new ArrayList();
4
		fooBag.add( new Foo() );
5
		fooBag
3
Category c = new Category();
4
		List list = new ArrayList();
5
		c.setSubcategories(list);
6
.add( new Foo() );
6
		list.add( new Category() );
7
		baz.setFooBag(fooBag);
7
		c.set
8
		s.save(baz);
9
		s.flush();
10
		fooBag = baz.getFooBag();
11
		s.find("from Baz baz left join fetch baz.fooBag");
12
		assertTrue( fooBag==baz.getFooBag() 
8
Name("root");
9
		Serializable id = s.save(c);
13
);
10
		s.flush();
14
		s.connection().commit();
11
		s.connection().commit();
15
		s.close();
12
		s.close();
16
		s = openSession();
13
		s = openSession();
17
		baz = (Baz) s.load( Baz.class, baz.getCode() );
14
		c = (Category) s.load(
18
		Object bag = baz.getFooBag();
19
		assertFalse( Hibernate.isInitialized(bag) );
20
		s.find("from Baz baz left join fetch baz.fooBag");
21
		assertTrue( bag==baz.getFooBag() 
15
Category.class, id);
16
		s.refresh(c);
17
		s.flush();
18
		assertTrue( c.getSubcategories().size()==1 );
19
		s.flush();
20
		s.connection().commit();
21
		s.close();
22
		s = openSession();
22
);
23
		c = (Category) s.load(Category.class, id);
23
		assertTrue( baz.getFooBag().size()==2 );
24
		assertTrue( c.getSubcategories().size()==1 );
24
		s.delete(baz);
25
		s.delete(c);
25
		s.flush();
26
		s.flush();
26
		s.connection().commit();
27
		s.connection().commit();
27
		s.close();
28
		s.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 in different classes having the same super class
Number of node comparisons362
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements12
    Number of unmapped statements in the first code fragment12
    Number of unmapped statements in the second code fragment13
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
                                                              
    2
    Category c = new Category();
    2
    Baz baz = new Baz();
                                              
    3
    Collection fooBag = new ArrayList();
    3
    Collection fooBag = new ArrayList();
    3
    List list = new ArrayList();
    Differences
    Expression1Expression2Difference
    java.util.Collectionjava.util.ListSUBCLASS_TYPE_MISMATCH
    fooBaglistVARIABLE_NAME_MISMATCH
    java.util.Collectionjava.util.ListSUBCLASS_TYPE_MISMATCH
    3
    List list = new ArrayList();
                                                            
    4
    c.setSubcategories(list);
    Preondition Violations
    Unmatched statement c.setSubcategories(list); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4
    c.setSubcategories(list);
    4
    fooBag.add(new Foo());
    4
    fooBag.add(new Foo());
    Preondition Violations
    Unmatched statement fooBag.add(new Foo()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                      
    5
    fooBag.add(new Foo());
    5
    fooBag.add(new Foo());
    5
    list.add(new Category());
    Differences
    Expression1Expression2Difference
    org.hibernate.test.legacy.Fooorg.hibernate.test.legacy.CategoryVARIABLE_TYPE_MISMATCH
    fooBaglistVARIABLE_NAME_MISMATCH
    java.util.Collectionjava.util.ListSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.legacy.Foo does not match with type org.hibernate.test.legacy.Category
    • Make classes org.hibernate.test.legacy.Foo and org.hibernate.test.legacy.Category extend a common superclass
    5
    list.add(new Category());
                                              
    6
    c.setName("root");
    Preondition Violations
    Unmatched statement c.setName("root"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    6
    c.setName("root");
    6
    baz.setFooBag(fooBag);
    6
    baz.setFooBag(fooBag);
    Preondition Violations
    Unmatched statement baz.setFooBag(fooBag); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                      
                                                              
    7
    Serializable id = s.save(c);
    Preondition Violations
    Unmatched statement Serializable id=s.save(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7
    Serializable id = s.save(c);
    7
    s.save(baz);
    7
    s.save(baz);
    Preondition Violations
    Unmatched statement s.save(baz); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                  
    8
    s.flush();
    8
    s.flush();
    9
    fooBag = baz.getFooBag();
    9
    fooBag = baz.getFooBag();
    Preondition Violations
    Unmatched statement fooBag=baz.getFooBag(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                        
    10
    s.find("from Baz baz left join fetch baz.fooBag");
    10
    s.find("from Baz baz left join fetch baz.fooBag");
    Preondition Violations
    Unmatched statement s.find("from Baz baz left join fetch baz.fooBag"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                
    11
    assertTrue(fooBag == baz.getFooBag());
                                                                                        
    12
    s.connection().commit();
    9
    s.connection().commit();
    13
    s.close();
    10
    s.close();
    14
    s = openSession();
    11
    s = openSession();
                                                                                        
    12
    c = (Category)s.load(Category.class, id);
    Preondition Violations
    Unmatched statement c=(Category)s.load(Category.class,id); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    c = (Category)s.load(Category.class, id);
                                      
    13
    s.refresh(c);
    Preondition Violations
    Unmatched statement s.refresh(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13
    s.refresh(c);
                                
    14
    s.flush();
    Preondition Violations
    Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14
    s.flush();
    15
    baz = (Baz)s.load(Baz.class, baz.getCode());
    15
    baz = (Baz)s.load(Baz.class, baz.getCode());
    Preondition Violations
    Unmatched statement baz=(Baz)s.load(Baz.class,baz.getCode()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                              
    16
    Object bag = baz.getFooBag();
                                                                  
    17
    assertFalse(Hibernate.isInitialized(bag));
    17
    assertFalse(Hibernate.isInitialized(bag));
    15
    assertTrue(c.getSubcategories().size() == 1);
    Differences
    Expression1Expression2Difference
    Hibernate.isInitialized(bag)c.getSubcategories().size() == 1TYPE_COMPATIBLE_REPLACEMENT
    assertFalseassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression Hibernate.isInitialized(bag) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression c.getSubcategories().size() == 1 cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertFalse(Hibernate.isInitialized(bag)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(c.getSubcategories().size() == 1) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertFalse(Hibernate.isInitialized(bag)) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(c.getSubcategories().size() == 1) is a void method call, and thus it cannot be parameterized
    15
    assertTrue(c.getSubcategories().size() == 1);
                                                            
    17
    s.connection().commit();
    Preondition Violations
    Unmatched statement s.connection().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17
    s.connection().commit();
                                
    18
    s.close();
    Preondition Violations
    Unmatched statement s.close(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    18
    s.close();
    18
    s.find("from Baz baz left join fetch baz.fooBag");
    18
    s.find("from Baz baz left join fetch baz.fooBag");
    Preondition Violations
    Unmatched statement s.find("from Baz baz left join fetch baz.fooBag"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                
                                            
    19
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19
    s = openSession();
    19
    assertTrue(bag == baz.getFooBag());
                                                                                  
    20
    assertTrue(baz.getFooBag().size() == 2);
                                                                                            
    21
    s.delete(baz);
    21
    s.delete(baz);
    16
    s.flush();
    Differences
    Expression1Expression2Difference
    deleteflushMETHOD_INVOCATION_NAME_MISMATCH
    s.delete(baz)s.flush()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression s.delete(baz) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(baz) is a void method call, and thus it cannot be parameterized
    Expression s.flush() is a void method call, and thus it cannot be parameterized
    Expression s.delete(baz) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(baz) is a void method call, and thus it cannot be parameterized
    Expression s.flush() is a void method call, and thus it cannot be parameterized
    16
    s.flush();
                                                                                        
    20
    c = (Category)s.load(Category.class, id);
    Preondition Violations
    Unmatched statement c=(Category)s.load(Category.class,id); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    20
    c = (Category)s.load(Category.class, id);
                                                                                                      
    21
    assertTrue(c.getSubcategories().size() == 1);
                                    
    22
    s.delete(c);
    22
    s.flush();
    23
    s.flush();
    23
    s.connection().commit();
    24
    s.connection().commit();
    24
    s.close();
    25
    s.close();
    Precondition Violations (33)
    Row Violation
    1Unmatched statement c.setSubcategories(list); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement fooBag.add(new Foo()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Type org.hibernate.test.legacy.Foo does not match with type org.hibernate.test.legacy.Category
    4Unmatched statement c.setName("root"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    5Unmatched statement baz.setFooBag(fooBag); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement Serializable id=s.save(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched statement s.save(baz); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Unmatched statement fooBag=baz.getFooBag(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9Unmatched statement s.find("from Baz baz left join fetch baz.fooBag"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Unmatched statement c=(Category)s.load(Category.class,id); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Unmatched statement s.refresh(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Unmatched statement baz=(Baz)s.load(Baz.class,baz.getCode()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14Expression Hibernate.isInitialized(bag) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression c.getSubcategories().size() == 1 cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Expression assertFalse(Hibernate.isInitialized(bag)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression assertTrue(c.getSubcategories().size() == 1) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression assertFalse(Hibernate.isInitialized(bag)) is a void method call, and thus it cannot be parameterized
    19Expression assertTrue(c.getSubcategories().size() == 1) is a void method call, and thus it cannot be parameterized
    20Unmatched statement s.connection().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Unmatched statement s.close(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    22Unmatched statement s.find("from Baz baz left join fetch baz.fooBag"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    23Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    24Expression s.delete(baz) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    26Expression s.delete(baz) is a void method call, and thus it cannot be parameterized
    27Expression s.flush() is a void method call, and thus it cannot be parameterized
    28Expression s.delete(baz) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    29Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    30Expression s.delete(baz) is a void method call, and thus it cannot be parameterized
    31Expression s.flush() is a void method call, and thus it cannot be parameterized
    32Unmatched statement c=(Category)s.load(Category.class,id); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    33Clone fragment #1 returns variables fooBag, s , while Clone fragment #2 returns variables list, s