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 statements13
    Number of unmapped statements in the first code fragment11
    Number of unmapped statements in the second code fragment12
    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
    List list = new ArrayList();
    3
    Collection fooBag = new ArrayList();
                                                                              
                                                            
    4
    c.setSubcategories(list);
    4
    fooBag.add(new Foo());
    4
    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.ListVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.legacy.Foo of variable new Foo() does not match with type org.hibernate.test.legacy.Category of variable new Category()
    • Make classes org.hibernate.test.legacy.Foo and org.hibernate.test.legacy.Category extend a common superclass
    Type java.util.Collection of variable fooBag does not match with type java.util.List of variable list
    • Make classes java.util.Collection and java.util.List extend a common superclass
    5
    list.add(new Category());
    5
    fooBag.add(new Foo());
                                                      
                                              
    6
    c.setName("root");
    6
    baz.setFooBag(fooBag);
                                                      
                                                              
    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());
    11
    assertTrue(fooBag == baz.getFooBag());
    14
    s.flush();
    Differences
    Expression1Expression2Difference
    assertTrueflushMETHOD_INVOCATION_NAME_MISMATCH
    assertTrue(fooBag == baz.getFooBag())s.flush()ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(fooBag == baz.getFooBag()) 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.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(fooBag == baz.getFooBag()) 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
    14
    s.flush();
    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);
    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
    assertFalseassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    Hibernate.isInitialized(bag)c.getSubcategories().size() == 1TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    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);
    18
    s.find("from Baz baz left join fetch baz.fooBag");
                                                                                                                
    19
    assertTrue(bag == baz.getFooBag());
    19
    assertTrue(bag == baz.getFooBag());
    17
    s.connection().commit();
    Differences
    Expression1Expression2Difference
    assertTruecommitMETHOD_INVOCATION_NAME_MISMATCH
    assertTrue(bag == baz.getFooBag())s.connection().commit()ARGUMENT_NUMBER_MISMATCH
    s.connection()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.connection().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(bag == baz.getFooBag()) is a void method call, and thus it cannot be parameterized
    Expression s.connection().commit() is a void method call, and thus it cannot be parameterized
    Expression s.connection().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(bag == baz.getFooBag()) is a void method call, and thus it cannot be parameterized
    Expression s.connection().commit() is a void method call, and thus it cannot be parameterized
    17
    s.connection().commit();
    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();
                                
    18
    s.close();
                                            
    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();
                                                                                        
    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 (32)
    Row Violation
    1Type org.hibernate.test.legacy.Foo of variable new Foo() does not match with type org.hibernate.test.legacy.Category of variable new Category()
    2Type java.util.Collection of variable fooBag does not match with type java.util.List of variable list
    3Unmatched 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
    4Unmatched statement s.save(baz); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement fooBag=baz.getFooBag(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched 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
    7Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression assertTrue(fooBag == baz.getFooBag()) is a void method call, and thus it cannot be parameterized
    9Expression s.flush() is a void method call, and thus it cannot be parameterized
    10Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression assertTrue(fooBag == baz.getFooBag()) is a void method call, and thus it cannot be parameterized
    12Expression s.flush() is a void method call, and thus it cannot be parameterized
    13Unmatched 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
    14Unmatched 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
    15Expression assertFalse(Hibernate.isInitialized(bag)) is a void method call, and thus it cannot be parameterized
    16Expression assertTrue(c.getSubcategories().size() == 1) is a void method call, and thus it cannot be parameterized
    17Expression s.connection().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression assertTrue(bag == baz.getFooBag()) is a void method call, and thus it cannot be parameterized
    19Expression s.connection().commit() is a void method call, and thus it cannot be parameterized
    20Expression s.connection().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21Expression assertTrue(bag == baz.getFooBag()) is a void method call, and thus it cannot be parameterized
    22Expression s.connection().commit() is a void method call, and thus it cannot be parameterized
    23Expression s.delete(baz) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    24Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Expression s.delete(baz) is a void method call, and thus it cannot be parameterized
    26Expression s.flush() is a void method call, and thus it cannot be parameterized
    27Expression s.delete(baz) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    28Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    29Expression s.delete(baz) is a void method call, and thus it cannot be parameterized
    30Expression s.flush() is a void method call, and thus it cannot be parameterized
    31Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    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