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.list().get(0); 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 testSelectClauseImplicitJoin() 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.list()
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);
24
.get(0);
23
		s.delete( l.get(0) );
25
		assertEquals( zoo.getMammals().size(), 1 );
24
		
26
		assertEquals( zoo.getAnimals().size(), 1 );
27
		s.clear(
25
s.delete( l.get(1) );
26
		s.delete( l.get(2) );
28
);
27
		s.delete( l.get(3) );
29
		s.delete(plat);
28
		s.delete(
30
		s.delete(zoo);
31
		t
29
 l.get(4) );
30
		s.flush();
32
.commit();
31
		s.connection().commit();
33
		s.close();
32
		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 statements4
    Number of unmapped statements in the first code fragment25
    Number of unmapped statements in the second code fragment24
    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();
    1
    Session s = openSession();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    1
    Session s = openSession();
                                                
    2
    Qux q = new Qux("0");
    Preondition Violations
    Unmatched statement Qux q=new Qux("0"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2
    Qux q = new Qux("0");
    2
    Transaction t = s.beginTransaction();
    2
    Transaction t = s.beginTransaction();
    Preondition Violations
    Unmatched statement Transaction t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                
                              
    3
    s.save(q);
    Preondition Violations
    Unmatched statement s.save(q); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3
    s.save(q);
    3
    Zoo zoo = new Zoo();
                                              
                                                            
    4
    q.setChild(new Qux("1"));
    Preondition Violations
    Unmatched statement q.setChild(new Qux("1")); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4
    q.setChild(new Qux("1"));
    4
    zoo.setName("The Zoo");
    4
    zoo.setName("The Zoo");
    Preondition Violations
    Unmatched statement zoo.setName("The Zoo"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                        
                                                    
    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());
    5
    zoo.setMammals(new HashMap());
    Preondition Violations
    Unmatched statement zoo.setMammals(new HashMap()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                      
                                                  
    6
    Qux q2 = new Qux("2");
    Preondition Violations
    Unmatched statement Qux q2=new Qux("2"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    6
    Qux q2 = new Qux("2");
    6
    zoo.setAnimals(new HashMap());
    6
    zoo.setAnimals(new HashMap());
    Preondition Violations
    Unmatched statement zoo.setAnimals(new HashMap()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                      
                                                              
    7
    q2.setChild(q.getChild());
    Preondition Violations
    Unmatched statement q2.setChild(q.getChild()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    7
    q2.setChild(q.getChild());
    7
    Mammal plat = new Mammal();
                                                            
                                                  
    8
    Qux q3 = new Qux("3");
    Preondition Violations
    Unmatched statement Qux q3=new Qux("3"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    8
    Qux q3 = new Qux("3");
    8
    plat.setBodyWeight(11f);
    8
    plat.setBodyWeight(11f);
    Preondition Violations
    Unmatched statement plat.setBodyWeight(11f); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                          
                                                              
    9
    q.getChild().setChild(q3);
    Preondition Violations
    Unmatched statement q.getChild().setChild(q3); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    9
    q.getChild().setChild(q3);
    9
    plat.setDescription("Platypus");
    9
    plat.setDescription("Platypus");
    Preondition Violations
    Unmatched statement plat.setDescription("Platypus"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                          
                                  
    10
    s.save(q3);
    Preondition Violations
    Unmatched statement s.save(q3); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10
    s.save(q3);
    10
    plat.setZoo(zoo);
    10
    plat.setZoo(zoo);
    Preondition Violations
    Unmatched statement plat.setZoo(zoo); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                              
                                                    
    11
    Qux q4 = new Qux("4");
    Preondition Violations
    Unmatched statement Qux q4=new Qux("4"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    11
    Qux q4 = new Qux("4");
    11
    plat.setSerialNumber("plat123");
    11
    plat.setSerialNumber("plat123");
    Preondition Violations
    Unmatched statement plat.setSerialNumber("plat123"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                            
                                            
    12
    q4.setChild(q3);
    Preondition Violations
    Unmatched statement q4.setChild(q3); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    12
    q4.setChild(q3);
    12
    zoo.getMammals().put("Platypus", plat);
                                                                                        
                                  
    13
    s.save(q4);
    Preondition Violations
    Unmatched statement s.save(q4); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13
    s.save(q4);
    13
    zoo.getAnimals().put("plat123", plat);
                                                                                      
                                  
    14
    s.save(q2);
    Preondition Violations
    Unmatched statement s.save(q2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14
    s.save(q2);
    14
    s.persist(plat);
    14
    s.persist(plat);
    Preondition Violations
    Unmatched statement s.persist(plat); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                            
    15
    s.persist(zoo);
    15
    s.persist(zoo);
    Preondition Violations
    Unmatched statement s.persist(zoo); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                          
    16
    s.flush();
    16
    s.flush();
    15
    s.flush();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    15
    s.flush();
                                                            
    16
    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
    16
    s.connection().commit();
    17
    s.clear();
    17
    s.clear();
    Preondition Violations
    Unmatched statement s.clear(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                
                                            
    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();
    18
    Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");
    18
    Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");
    Preondition Violations
    Unmatched statement Query q=s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                      
                                                                
    19
    List l = s.find("from Qux");
    Preondition Violations
    Unmatched statement List l=s.find("from Qux"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    19
    List l = s.find("from Qux");
    19
    Type type = q.getReturnTypes()[0];
                                                                            
    20
    assertTrue(type instanceof ManyToOneType);
    20
    assertTrue(type instanceof ManyToOneType);
    20
    assertTrue("", l.size() == 5);
    Differences
    Expression1Expression2Difference
    assertTrue(type instanceof ManyToOneType)assertTrue("",l.size() == 5)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertTrue(type instanceof ManyToOneType) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue("",l.size() == 5) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(type instanceof ManyToOneType) 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);
                                                  
    21
    s.delete(l.get(0));
    21
    assertEquals(((ManyToOneType)type).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo");
                                                                                                                                                                                                  
                                                  
    22
    s.delete(l.get(1));
    22
    zoo = (Zoo)q.list().get(0);
    22
    zoo = (Zoo)q.list().get(0);
    Preondition Violations
    Unmatched statement zoo=(Zoo)q.list().get(0); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                              
                                                  
    23
    s.delete(l.get(2));
    23
    assertEquals(zoo.getMammals().size(), 1);
                                                                                            
                                                  
    24
    s.delete(l.get(3));
    24
    assertEquals(zoo.getAnimals().size(), 1);
                                                                                            
                                                  
    25
    s.delete(l.get(4));
    25
    s.clear();
    25
    s.clear();
    Preondition Violations
    Unmatched statement s.clear(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                
                                
    26
    s.flush();
    26
    s.delete(plat);
    26
    s.delete(plat);
    Preondition Violations
    Unmatched statement s.delete(plat); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                          
                                                            
    27
    s.connection().commit();
    27
    s.delete(zoo);
    27
    s.delete(zoo);
    Preondition Violations
    Unmatched statement s.delete(zoo); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                        
                                
    28
    s.close();
    28
    t.commit();
    28
    t.commit();
    Preondition Violations
    Unmatched statement t.commit(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                  
    29
    s.close();
    29
    s.close();
    17
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    17
    s.close();
    Precondition Violations (38)
    Row Violation
    1Unmatched statement Qux q=new Qux("0"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement Transaction t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement s.save(q); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement q.setChild(new Qux("1")); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    5Unmatched statement zoo.setName("The Zoo"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    6Unmatched 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
    7Unmatched statement zoo.setMammals(new HashMap()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    8Unmatched statement Qux q2=new Qux("2"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    9Unmatched statement zoo.setAnimals(new HashMap()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    10Unmatched statement q2.setChild(q.getChild()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    11Unmatched statement Qux q3=new Qux("3"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    12Unmatched statement plat.setBodyWeight(11f); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    13Unmatched statement q.getChild().setChild(q3); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    14Unmatched statement plat.setDescription("Platypus"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    15Unmatched statement s.save(q3); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16Unmatched statement plat.setZoo(zoo); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    17Unmatched statement Qux q4=new Qux("4"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    18Unmatched statement plat.setSerialNumber("plat123"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    19Unmatched statement q4.setChild(q3); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    20Unmatched statement s.save(q4); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Unmatched statement s.save(q2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    22Unmatched statement s.persist(plat); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    23Unmatched statement s.persist(zoo); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    24Unmatched statement s.connection().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    25Unmatched statement s.clear(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    26Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    27Unmatched statement Query q=s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    28Unmatched statement List l=s.find("from Qux"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    29Expression assertTrue(type instanceof ManyToOneType) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    30Expression assertTrue("",l.size() == 5) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    31Expression assertTrue(type instanceof ManyToOneType) is a void method call, and thus it cannot be parameterized
    32Expression assertTrue("",l.size() == 5) is a void method call, and thus it cannot be parameterized
    33Unmatched statement zoo=(Zoo)q.list().get(0); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    34Unmatched statement s.clear(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    35Unmatched statement s.delete(plat); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    36Unmatched statement s.delete(zoo); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    37Unmatched statement t.commit(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    38Clone fragment #1 returns variable s with type org.hibernate.Session , while Clone fragment #2 returns variable s with type org.hibernate.classic.Session