Session s = openSession(); Transaction t = s.beginTransaction(); Zoo zoo = new Zoo(); zoo.setName("The Zoo"); zoo.setMammals( new HashMap() ); zoo.setAnimals( new HashMap() ); Mammal plat = new Mammal(); plat.setBodyWeight( 11f ); plat.setDescription( "Platypus" ); plat.setZoo(zoo); plat.setSerialNumber("plat123"); zoo.getMammals().put("Platypus", plat); zoo.getAnimals().put("plat123", plat); s.persist( plat ); s.persist(zoo); s.flush(); s.clear(); Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null"); Type type = q.getReturnTypes()[0]; assertTrue( type instanceof ManyToOneType ); assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" ); zoo = (Zoo) q .iterate().next(); assertEquals( zoo.getMammals().size(), 1 ); assertEquals( zoo.getAnimals().size(), 1 ); s.clear(); s.delete(plat); s.delete(zoo); t.commit(); s.close();
Session s = openSession(); Qux q = new Qux("0"); s.save(q); q.setChild( new Qux("1") ); s.save( q.getChild() ); Qux q2 = new Qux("2"); q2.setChild( q.getChild() ); Qux q3 = new Qux("3"); q.getChild().setChild(q3); s.save(q3); Qux q4 = new Qux("4"); q4.setChild(q3); s.save(q4); s.save(q2); s.flush(); s.connection().commit(); s.close(); s = openSession(); List l = s.find("from Qux"); assertTrue( "", l.size()==5); s.delete( l.get(0) ); s.delete( l.get(1) ); s.delete( l.get(2) ); s.delete( l.get(3) ); s.delete( l.get(4) ); 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/hql/ASTParserLoadingTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java
Method name: void testSelectClauseImplicitJoinWithIterate() Method name: void testCallback()
Number of AST nodes: 29 Number of AST nodes: 28
1
Session s = openSession();
1
Session s = openSession();
2
		Transaction t = s.beginTransaction();
2
		
3
		Zoo zoo = new Zoo();
4
		zoo.setName("The Zoo"
3
Qux q = new Qux("0");
5
);
4
		s.save(q);
6
		zoo.setMammals( new HashMap() );
5
		q.set
7
		zoo.setAnimals( new HashMap() );
8
		Mammal plat = new Mammal();
9
		plat.setBodyWeight( 11f );
10
		plat.setDescription( "Platypus" );
11
		plat.setZoo(zoo);
12
		plat.setSerialNumber("plat123");
13
		zoo.getMammals().put("Platypus", plat);
14
		zoo.getAnimals().put("plat123", plat);
15
		s.persist( plat );
16
		s.persist(zoo);
17
		s.flush();
18
		s.clear();
19
		Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");
20
		Type type = q.getReturnTypes()[0];
21
		assertTrue( type instanceof ManyToOneType );
22
		assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );
23
		zoo = (Zoo) q
24
			.iterate().next();
25
		assertEquals( zoo.getMammals().size(), 1 );
26
		assertEquals( zoo.getAnimals().size(), 1 );
27
		s.clear();
28
		s.delete(plat);
29
		s.delete(zoo);
30
		t
6
Child( new Qux("1") );
7
		s.save( q.getChild() );
8
		Qux q2 = new Qux("2");
9
		q2.setChild( q.getChild() );
10
		Qux q3 = new Qux("3");
11
		q.getChild().setChild(q3);
12
		s.save(q3);
13
		Qux q4 = new Qux("4");
14
		q4.setChild(q3);
15
		s.save(q4);
16
		s.save(q2);
17
		s.flush();
18
		s.connection().commit();
19
		s.close();
20
		s = openSession();
21
		List l = s.find("from Qux");
22
		assertTrue( "", l.size()==5);
23
		s.delete( l.get(0) );
24
		s.delete( l.get(1) );
25
		s.delete( l.get(2) );
26
		s.delete( l.get(3) );
27
		s.delete( l.get(4) );
28
		s.flush();
31
.commit();
29
		s.connection().commit();
32
		s.close();
30
		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 comparisons812
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements8
    Number of unmapped statements in the first code fragment21
    Number of unmapped statements in the second code fragment20
    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
    Qux q = new Qux("0");
    2
    Transaction t = s.beginTransaction();
                                                                                
                              
    3
    s.save(q);
    3
    Zoo zoo = new Zoo();
                                              
    4
    zoo.setName("The Zoo");
                                                        
                                                    
    5
    s.save(q.getChild());
    Preondition Violations
    Unmatched statement s.save(q.getChild()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5
    s.save(q.getChild());
    5
    zoo.setMammals(new HashMap());
                                                                      
                                                  
    6
    Qux q2 = new Qux("2");
    6
    zoo.setAnimals(new HashMap());
                                                                      
    7
    Mammal plat = new Mammal();
                                                            
                                                  
    8
    Qux q3 = new Qux("3");
    8
    plat.setBodyWeight(11f);
                                                          
    9
    plat.setDescription("Platypus");
                                                                          
    10
    plat.setZoo(zoo);
                                              
    11
    plat.setSerialNumber("plat123");
                                                                            
    12
    zoo.getMammals().put("Platypus", plat);
                                                                                        
    13
    zoo.getAnimals().put("plat123", plat);
                                                                                      
    14
    s.persist(plat);
                                            
    15
    s.persist(zoo);
                                          
    16
    s.flush();
    16
    s.flush();
    15
    s.flush();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    15
    s.flush();
    17
    s.clear();
    17
    s.clear();
    20
    assertTrue("", l.size() == 5);
    Differences
    Expression1Expression2Difference
    clearassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    s.clear()assertTrue("",l.size() == 5)ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.clear() is a void method call, and thus it cannot be parameterized
    Expression assertTrue("",l.size() == 5) is a void method call, and thus it cannot be parameterized
    Expression s.clear() is a void method call, and thus it cannot be parameterized
    Expression assertTrue("",l.size() == 5) is a void method call, and thus it cannot be parameterized
    20
    assertTrue("", l.size() == 5);
    18
    Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");
                                                                                                                                                                                      
    19
    Type type = q.getReturnTypes()[0];
                                                                            
    20
    assertTrue(type instanceof ManyToOneType);
    20
    assertTrue(type instanceof ManyToOneType);
    4
    q.setChild(new Qux("1"));
    Differences
    Expression1Expression2Difference
    assertTruesetChildMETHOD_INVOCATION_NAME_MISMATCH
    qMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertTrue(type instanceof ManyToOneType) is a void method call, and thus it cannot be parameterized
    Expression q.setChild(new Qux("1")) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(type instanceof ManyToOneType) is a void method call, and thus it cannot be parameterized
    Expression q.setChild(new Qux("1")) is a void method call, and thus it cannot be parameterized
    4
    q.setChild(new Qux("1"));
    21
    assertEquals(((ManyToOneType)type).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo");
    21
    assertEquals(((ManyToOneType)type).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo");
    12
    q4.setChild(q3);
    Differences
    Expression1Expression2Difference
    assertEqualssetChildMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(((ManyToOneType)type).getAssociatedEntityName(),"org.hibernate.test.hql.Zoo")q4.setChild(q3)ARGUMENT_NUMBER_MISMATCH
    q4MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals(((ManyToOneType)type).getAssociatedEntityName(),"org.hibernate.test.hql.Zoo") is a void method call, and thus it cannot be parameterized
    Expression q4.setChild(q3) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(((ManyToOneType)type).getAssociatedEntityName(),"org.hibernate.test.hql.Zoo") is a void method call, and thus it cannot be parameterized
    Expression q4.setChild(q3) is a void method call, and thus it cannot be parameterized
    12
    q4.setChild(q3);
    22
    zoo = (Zoo)q.iterate().next();
                                                                    
    23
    assertEquals(zoo.getMammals().size(), 1);
    23
    assertEquals(zoo.getMammals().size(), 1);
    9
    q.getChild().setChild(q3);
    Differences
    Expression1Expression2Difference
    assertEqualssetChildMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(zoo.getMammals().size(),1)q.getChild().setChild(q3)ARGUMENT_NUMBER_MISMATCH
    q.getChild()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression q.getChild().setChild(q3) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(zoo.getMammals().size(),1) is a void method call, and thus it cannot be parameterized
    Expression q.getChild().setChild(q3) is a void method call, and thus it cannot be parameterized
    Expression q.getChild().setChild(q3) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(zoo.getMammals().size(),1) is a void method call, and thus it cannot be parameterized
    Expression q.getChild().setChild(q3) is a void method call, and thus it cannot be parameterized
    9
    q.getChild().setChild(q3);
    24
    assertEquals(zoo.getAnimals().size(), 1);
    24
    assertEquals(zoo.getAnimals().size(), 1);
    7
    q2.setChild(q.getChild());
    Differences
    Expression1Expression2Difference
    assertEqualssetChildMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(zoo.getAnimals().size(),1)q2.setChild(q.getChild())ARGUMENT_NUMBER_MISMATCH
    q2MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals(zoo.getAnimals().size(),1) is a void method call, and thus it cannot be parameterized
    Expression q2.setChild(q.getChild()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(zoo.getAnimals().size(),1) is a void method call, and thus it cannot be parameterized
    Expression q2.setChild(q.getChild()) is a void method call, and thus it cannot be parameterized
    7
    q2.setChild(q.getChild());
                                  
    10
    s.save(q3);
                                                    
    11
    Qux q4 = new Qux("4");
                                  
    13
    s.save(q4);
                                  
    14
    s.save(q2);
                                                            
    16
    s.connection().commit();
                                            
    18
    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
    18
    s = openSession();
                                                                
    19
    List l = s.find("from Qux");
                                                  
    21
    s.delete(l.get(0));
                                                  
    22
    s.delete(l.get(1));
                                                  
    23
    s.delete(l.get(2));
                                                  
    24
    s.delete(l.get(3));
                                                  
    25
    s.delete(l.get(4));
    25
    s.clear();
    25
    s.clear();
    26
    s.flush();
    Differences
    Expression1Expression2Difference
    clearflushMETHOD_INVOCATION_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Expression s.clear() 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
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    26
    s.flush();
    26
    s.delete(plat);
                                          
                                                            
    27
    s.connection().commit();
    27
    s.delete(zoo);
                                        
    28
    t.commit();
                                  
    29
    s.close();
    29
    s.close();
    17
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    17
    s.close();
                                
    28
    s.close();
    Precondition Violations (29)
    Row Violation
    1Unmatched statement s.save(q.getChild()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    3Expression s.clear() is a void method call, and thus it cannot be parameterized
    4Expression assertTrue("",l.size() == 5) is a void method call, and thus it cannot be parameterized
    5Expression s.clear() is a void method call, and thus it cannot be parameterized
    6Expression assertTrue("",l.size() == 5) is a void method call, and thus it cannot be parameterized
    7Expression assertTrue(type instanceof ManyToOneType) is a void method call, and thus it cannot be parameterized
    8Expression q.setChild(new Qux("1")) is a void method call, and thus it cannot be parameterized
    9Expression assertTrue(type instanceof ManyToOneType) is a void method call, and thus it cannot be parameterized
    10Expression q.setChild(new Qux("1")) is a void method call, and thus it cannot be parameterized
    11Expression assertEquals(((ManyToOneType)type).getAssociatedEntityName(),"org.hibernate.test.hql.Zoo") is a void method call, and thus it cannot be parameterized
    12Expression q4.setChild(q3) is a void method call, and thus it cannot be parameterized
    13Expression assertEquals(((ManyToOneType)type).getAssociatedEntityName(),"org.hibernate.test.hql.Zoo") is a void method call, and thus it cannot be parameterized
    14Expression q4.setChild(q3) is a void method call, and thus it cannot be parameterized
    15Expression q.getChild().setChild(q3) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Expression assertEquals(zoo.getMammals().size(),1) is a void method call, and thus it cannot be parameterized
    17Expression q.getChild().setChild(q3) is a void method call, and thus it cannot be parameterized
    18Expression q.getChild().setChild(q3) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19Expression assertEquals(zoo.getMammals().size(),1) is a void method call, and thus it cannot be parameterized
    20Expression q.getChild().setChild(q3) is a void method call, and thus it cannot be parameterized
    21Expression assertEquals(zoo.getAnimals().size(),1) is a void method call, and thus it cannot be parameterized
    22Expression q2.setChild(q.getChild()) is a void method call, and thus it cannot be parameterized
    23Expression assertEquals(zoo.getAnimals().size(),1) is a void method call, and thus it cannot be parameterized
    24Expression q2.setChild(q.getChild()) is a void method call, and thus it cannot be parameterized
    25Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    26Expression s.clear() 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
    28Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    29Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s