Session s = openSession(); Transaction t = s.beginTransaction(); // create a new thing with a null name Thing thing = new Thing(); thing.setName(null); s.save(thing); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); List things = s.createQuery("from Thing").list(); assertEquals(1, things.size()); thing = (Thing)things.get(0); assertNull(thing.getName()); t.commit(); s.close(); // change detached thing name to a non-null value thing.setName("two"); s = openSession(); t = s.beginTransaction(); s.update(thing); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); things = s.createQuery("from Thing").list(); assertEquals(1, things.size()); thing = ((Thing) things.get(0)); assertEquals("two", thing.getName()); s.delete(thing); t.commit(); s.close();
Session s = openSession(); Transaction t = s.beginTransaction(); Person gavin = new Person("Gavin"); new Task("Code", gavin); s.persist(gavin); t.commit(); s.close(); assertEquals(0, gavin.getVersion()); s = openSession(); t = s.beginTransaction(); gavin = (Person) s.createCriteria(Person.class).uniqueResult(); new Task("Document", gavin); t.commit(); s.close(); assertEquals(0, gavin.getVersion()); assertFalse( Hibernate.isInitialized( gavin.getTasks() ) ); s = openSession(); t = s.beginTransaction(); gavin = (Person) s.createCriteria(Person.class).uniqueResult(); gavin.getTasks().clear(); t.commit(); s.close(); assertEquals(0, gavin.getVersion()); assertTrue( Hibernate.isInitialized( gavin.getTasks() ) ); s = openSession(); t = s.beginTransaction(); s.delete(gavin); t.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/join/OptionalJoinTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/version/VersionTest.java
Method name: void testUpdateNullOptionalJoinToNonNullDetached() Method name: void testCollectionNoVersion()
Number of AST nodes: 30 Number of AST nodes: 29
1
Session s = openSession();
1
Session s = openSession();
2
		Transaction t = s.beginTransaction();
2
		Transaction t = s.beginTransaction();
3
		// create a new thing with a null name
3
		
4
		Thing thing = new Thing();
4
Person gavin = new 
5
		thing.setName(null);
6
		s.save(th
5
Person("Gavin");
6
		new Task("Code", gavin);
7
ing);
7
		s.persist(gavin);
8
		t.commit();
8
		t.commit();
9
		s.close();
9
		s.close();
10
		
11
		assertEquals(0, gavin.getVersion());
12
		
10
		s = openSession();
13
		s = openSession();
11
		t = s.beginTransaction();
14
		t = s.beginTransaction();
12
		List things = s.createQuery("from Thing").list();
15
		
13
		assertEquals(1, things.size());
16
gavin = (Person) s.createCriteria(Person.class).uniqueResult();
14
		thing = (Thing)things.get(0);
17
		
15
		assertNull(thing.getName());
18
new Task("Document", gavin);
16
		t.commit();
19
		t.commit();
17
		s.close();
20
		s.close();
21
		
18
		// change detached thing name to a non-null value
22
		
19
		thing.setName("two");
20
		s = openSession();
21
		t = s.beginTransaction();
22
		s.update(thing
23
assertEquals(0, gavin.getVersion());
24
		assertFalse( Hibernate.isInitialized( gavin.getTasks() ) );
25
		s = openSession();
26
		t = s.beginTransaction();
27
		gavin = (Person) s.createCriteria(Person.class).uniqueResult();
23
);
28
		gavin.getTasks().clear();
24
		t.commit();
29
		t.commit();
25
		s.close();
30
		s.close();
31
		
26
		s = openSession();
32
		
27
		t = s.beginTransaction();
33
assertEquals(0, gavin.getVersion());
28
		things = s.createQuery("from Thing").list();
34
		
29
		assertEquals(1, things.size());
35
assertTrue( Hibernate.isInitialized( gavin.getTasks() ) );
30
		thing = ((Thing) things.get(0));
36
		
31
		assertEquals("two", thing.getName()
37
s = openSession();
32
);
38
		t = s.beginTransaction();
33
		s.delete(thing);
39
		s.delete(gavin);
34
		t.commit();
40
		t.commit();
35
		s.close();
41
		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 comparisons274
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements20
    Number of unmapped statements in the first code fragment10
    Number of unmapped statements in the second code fragment9
    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
    Transaction t = s.beginTransaction();
    2
    Transaction t = s.beginTransaction();
                                                                            
    3
    Person gavin = new Person("Gavin");
    Preondition Violations
    Unmatched statement Person gavin=new Person("Gavin"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3
    Person gavin = new Person("Gavin");
    3
    Thing thing = new Thing();
                                                          
                                                        
    4
    new Task("Code", gavin);
    4
    thing.setName(null);
    4
    thing.setName(null);
    Preondition Violations
    Unmatched statement thing.setName(null); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                  
                                            
    5
    s.persist(gavin);
    Preondition Violations
    Unmatched statement s.persist(gavin); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5
    s.persist(gavin);
    5
    s.save(thing);
    5
    s.save(thing);
    Preondition Violations
    Unmatched statement s.save(thing); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                      
    6
    t.commit();
    6
    t.commit();
    7
    s.close();
    7
    s.close();
    8
    s = openSession();
    9
    s = openSession();
    9
    t = s.beginTransaction();
    10
    t = s.beginTransaction();
    10
    List things = s.createQuery("from Thing").list();
    10
    List things = s.createQuery("from Thing").list();
    Preondition Violations
    Unmatched statement List things=s.createQuery("from Thing").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                          
                                                                                                                                    
    11
    gavin = (Person)s.createCriteria(Person.class).uniqueResult();
    Preondition Violations
    Unmatched statement gavin=(Person)s.createCriteria(Person.class).uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11
    gavin = (Person)s.createCriteria(Person.class).uniqueResult();
                                                                  
    12
    new Task("Document", gavin);
    11
    assertEquals(1, things.size());
    11
    assertEquals(1, things.size());
    16
    assertFalse(Hibernate.isInitialized(gavin.getTasks()));
    Differences
    Expression1Expression2Difference
    assertEqualsassertFalseMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,things.size())assertFalse(Hibernate.isInitialized(gavin.getTasks()))ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(1,things.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertFalse(Hibernate.isInitialized(gavin.getTasks())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    Expression assertFalse(Hibernate.isInitialized(gavin.getTasks())) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,things.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertFalse(Hibernate.isInitialized(gavin.getTasks())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    Expression assertFalse(Hibernate.isInitialized(gavin.getTasks())) is a void method call, and thus it cannot be parameterized
    16
    assertFalse(Hibernate.isInitialized(gavin.getTasks()));
    12
    thing = (Thing)things.get(0);
                                                                  
    13
    assertNull(thing.getName());
    13
    assertNull(thing.getName());
    8
    assertEquals(0, gavin.getVersion());
    Differences
    Expression1Expression2Difference
    assertNullassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    assertNull(thing.getName())assertEquals(0,gavin.getVersion())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertNull(thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(0,gavin.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(thing.getName()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(0,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    Expression assertNull(thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(0,gavin.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(thing.getName()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(0,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    8
    assertEquals(0, gavin.getVersion());
    14
    t.commit();
    13
    t.commit();
    15
    s.close();
    14
    s.close();
                                                                                  
    15
    assertEquals(0, gavin.getVersion());
    16
    thing.setName("two");
    16
    thing.setName("two");
    Preondition Violations
    Unmatched statement thing.setName("two"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                      
    17
    s = openSession();
    17
    s = openSession();
    18
    t = s.beginTransaction();
    18
    t = s.beginTransaction();
                                                                                                                                    
    19
    gavin = (Person)s.createCriteria(Person.class).uniqueResult();
    Preondition Violations
    Unmatched statement gavin=(Person)s.createCriteria(Person.class).uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19
    gavin = (Person)s.createCriteria(Person.class).uniqueResult();
    19
    s.update(thing);
    19
    s.update(thing);
    Preondition Violations
    Unmatched statement s.update(thing); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                            
                                                              
    20
    gavin.getTasks().clear();
    20
    t.commit();
    21
    t.commit();
    21
    s.close();
    22
    s.close();
                                                                                  
    23
    assertEquals(0, gavin.getVersion());
    22
    s = openSession();
    25
    s = openSession();
    23
    t = s.beginTransaction();
    26
    t = s.beginTransaction();
    24
    things = s.createQuery("from Thing").list();
    24
    things = s.createQuery("from Thing").list();
    Preondition Violations
    Unmatched statement things=s.createQuery("from Thing").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                
    25
    assertEquals(1, things.size());
    25
    assertEquals(1, things.size());
    24
    assertTrue(Hibernate.isInitialized(gavin.getTasks()));
    Differences
    Expression1Expression2Difference
    assertEqualsassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,things.size())assertTrue(Hibernate.isInitialized(gavin.getTasks()))ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(1,things.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(Hibernate.isInitialized(gavin.getTasks())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(Hibernate.isInitialized(gavin.getTasks())) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,things.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(Hibernate.isInitialized(gavin.getTasks())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(Hibernate.isInitialized(gavin.getTasks())) is a void method call, and thus it cannot be parameterized
    24
    assertTrue(Hibernate.isInitialized(gavin.getTasks()));
    26
    thing = ((Thing)things.get(0));
    26
    thing = ((Thing)things.get(0));
    Preondition Violations
    Unmatched statement thing=((Thing)things.get(0)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                      
    27
    assertEquals("two", thing.getName());
                                                                                    
    28
    s.delete(thing);
    28
    s.delete(thing);
    27
    s.delete(gavin);
    Differences
    Expression1Expression2Difference
    thinggavinVARIABLE_NAME_MISMATCH
    org.hibernate.test.join.Thingorg.hibernate.test.version.PersonVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.join.Thing of variable thing does not match with type org.hibernate.test.version.Person of variable gavin
    • Make classes org.hibernate.test.join.Thing and org.hibernate.test.version.Person extend a common superclass
    27
    s.delete(gavin);
    29
    t.commit();
    28
    t.commit();
    30
    s.close();
    29
    s.close();
    Precondition Violations (36)
    Row Violation
    1Unmatched statement Person gavin=new Person("Gavin"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement thing.setName(null); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement s.persist(gavin); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement s.save(thing); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement List things=s.createQuery("from Thing").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement gavin=(Person)s.createCriteria(Person.class).uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Expression assertEquals(1,things.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression assertFalse(Hibernate.isInitialized(gavin.getTasks())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    10Expression assertFalse(Hibernate.isInitialized(gavin.getTasks())) is a void method call, and thus it cannot be parameterized
    11Expression assertEquals(1,things.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression assertFalse(Hibernate.isInitialized(gavin.getTasks())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    14Expression assertFalse(Hibernate.isInitialized(gavin.getTasks())) is a void method call, and thus it cannot be parameterized
    15Expression assertNull(thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Expression assertEquals(0,gavin.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression assertNull(thing.getName()) is a void method call, and thus it cannot be parameterized
    18Expression assertEquals(0,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    19Expression assertNull(thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    20Expression assertEquals(0,gavin.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21Expression assertNull(thing.getName()) is a void method call, and thus it cannot be parameterized
    22Expression assertEquals(0,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    23Unmatched statement thing.setName("two"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    24Unmatched statement gavin=(Person)s.createCriteria(Person.class).uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    25Unmatched statement s.update(thing); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    26Unmatched statement things=s.createQuery("from Thing").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    27Expression assertEquals(1,things.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    28Expression assertTrue(Hibernate.isInitialized(gavin.getTasks())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    29Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    30Expression assertTrue(Hibernate.isInitialized(gavin.getTasks())) is a void method call, and thus it cannot be parameterized
    31Expression assertEquals(1,things.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    32Expression assertTrue(Hibernate.isInitialized(gavin.getTasks())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    33Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    34Expression assertTrue(Hibernate.isInitialized(gavin.getTasks())) is a void method call, and thus it cannot be parameterized
    35Unmatched statement thing=((Thing)things.get(0)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    36Type org.hibernate.test.join.Thing of variable thing does not match with type org.hibernate.test.version.Person of variable gavin