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.merge(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 Thing("Passport", 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 Thing("Laptop", gavin); t.commit(); s.close(); assertEquals(1, gavin.getVersion()); assertFalse( Hibernate.isInitialized( gavin.getThings() ) ); s = openSession(); t = s.beginTransaction(); gavin = (Person) s.createCriteria(Person.class).uniqueResult(); gavin.getThings().clear(); t.commit(); s.close(); assertEquals(2, gavin.getVersion()); assertTrue( Hibernate.isInitialized( gavin.getThings() ) ); 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 testMergeNullOptionalJoinToNonNullDetached() Method name: void testCollectionVersion()
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 Thing("Passport", 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());
14
		thing = (Thing)things.get(0);
15
		assertNull(thing.getName()
16
gavin = (Person) s.createCriteria(Person.class).uniqueResult();
16
);
17
		new Thing("Laptop", gavin);
17
		t.commit();
18
		t.commit();
18
		s.close();
19
		s.close();
20
		
19
		// change detached thing name to a non-null value
21
		
20
		thing.setName("two");
21
		s = openSession();
22
		t = s.beginTransaction();
23
		s.merge(thing
22
assertEquals(1, gavin.getVersion());
23
		assertFalse( Hibernate.isInitialized( gavin.getThings() ) );
24
		s = openSession();
25
		t = s.beginTransaction();
26
		gavin = (Person) s.createCriteria(Person.class).uniqueResult();
24
);
27
		gavin.getThings().clear();
25
		t.commit();
28
		t.commit();
26
		s.close();
29
		s.close();
30
		
27
		s = openSession();
31
		
28
		t = s.beginTransaction();
32
assertEquals(2, gavin.getVersion());
29
		things = s.createQuery("from Thing").list();
33
		
30
		assertEquals(1, things.size());
34
assertTrue( Hibernate.isInitialized( gavin.getThings() ) );
31
		thing = ((Thing) things.get(0));
35
		
32
		assertEquals("two", thing.getName()
36
s = openSession();
33
);
37
		t = s.beginTransaction();
34
		s.delete(thing);
38
		s.delete(gavin);
35
		t.commit();
39
		t.commit();
36
		s.close();
40
		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 statements23
    Number of unmapped statements in the first code fragment7
    Number of unmapped statements in the second code fragment6
    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");
    3
    Thing thing = new Thing();
                                                          
                                                                  
    4
    new Thing("Passport", gavin);
    4
    thing.setName(null);
    4
    thing.setName(null);
    16
    assertFalse(Hibernate.isInitialized(gavin.getThings()));
    Differences
    Expression1Expression2Difference
    setNameassertFalseMETHOD_INVOCATION_NAME_MISMATCH
    thingMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression thing.setName(null) is a void method call, and thus it cannot be parameterized
    Expression assertFalse(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    Expression thing.setName(null) is a void method call, and thus it cannot be parameterized
    Expression assertFalse(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    16
    assertFalse(Hibernate.isInitialized(gavin.getThings()));
    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
    assertEquals(1, things.size());
    11
    assertEquals(1, things.size());
    5
    s.persist(gavin);
    Differences
    Expression1Expression2Difference
    assertEqualspersistMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,things.size())s.persist(gavin)ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.persist(gavin) 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 s.persist(gavin) is a void method call, and thus it cannot be parameterized
    Expression s.persist(gavin) 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 s.persist(gavin) is a void method call, and thus it cannot be parameterized
    5
    s.persist(gavin);
    12
    thing = (Thing)things.get(0);
    12
    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
                                                                  
    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 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 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());
                                                                                                                                    
    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 Thing("Laptop", gavin);
    14
    t.commit();
    13
    t.commit();
    15
    s.close();
    14
    s.close();
    16
    thing.setName("two");
    16
    thing.setName("two");
    15
    assertEquals(1, gavin.getVersion());
    Differences
    Expression1Expression2Difference
    setNameassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    thing.setName("two")assertEquals(1,gavin.getVersion())ARGUMENT_NUMBER_MISMATCH
    thingMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression thing.setName("two") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression thing.setName("two") is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    Expression thing.setName("two") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression thing.setName("two") is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    15
    assertEquals(1, gavin.getVersion());
    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.merge(thing);
    19
    s.merge(thing);
    Preondition Violations
    Unmatched statement s.merge(thing); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                          
    20
    t.commit();
    21
    t.commit();
    21
    s.close();
    22
    s.close();
    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.getThings()));
    Differences
    Expression1Expression2Difference
    assertEqualsassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,things.size())assertTrue(Hibernate.isInitialized(gavin.getThings()))ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    24
    assertTrue(Hibernate.isInitialized(gavin.getThings()));
    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());
    27
    assertEquals("two", thing.getName());
    20
    gavin.getThings().clear();
    Differences
    Expression1Expression2Difference
    assertEqualsclearMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals("two",thing.getName())gavin.getThings().clear()ARGUMENT_NUMBER_MISMATCH
    gavin.getThings()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals("two",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("two",thing.getName()) is a void method call, and thus it cannot be parameterized
    Expression gavin.getThings().clear() is a void method call, and thus it cannot be parameterized
    Expression assertEquals("two",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("two",thing.getName()) is a void method call, and thus it cannot be parameterized
    Expression gavin.getThings().clear() is a void method call, and thus it cannot be parameterized
    20
    gavin.getThings().clear();
    28
    s.delete(thing);
    28
    s.delete(thing);
    23
    assertEquals(2, gavin.getVersion());
    Differences
    Expression1Expression2Difference
    deleteassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    s.delete(thing)assertEquals(2,gavin.getVersion())ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.delete(thing) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(thing) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(2,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    Expression s.delete(thing) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(thing) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(2,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    23
    assertEquals(2, gavin.getVersion());
                                            
    27
    s.delete(gavin);
    29
    t.commit();
    28
    t.commit();
    30
    s.close();
    29
    s.close();
    Precondition Violations (46)
    Row Violation
    1Expression thing.setName(null) is a void method call, and thus it cannot be parameterized
    2Expression assertFalse(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    3Expression thing.setName(null) is a void method call, and thus it cannot be parameterized
    4Expression assertFalse(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    5Unmatched statement s.save(thing); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched 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
    7Expression s.persist(gavin) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    9Expression s.persist(gavin) is a void method call, and thus it cannot be parameterized
    10Expression s.persist(gavin) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    12Expression s.persist(gavin) is a void method call, and thus it cannot be parameterized
    13Unmatched 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
    14Expression assertNull(thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression assertNull(thing.getName()) is a void method call, and thus it cannot be parameterized
    16Expression assertEquals(0,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    17Expression assertNull(thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression assertNull(thing.getName()) is a void method call, and thus it cannot be parameterized
    19Expression assertEquals(0,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    20Unmatched 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
    21Expression thing.setName("two") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression thing.setName("two") is a void method call, and thus it cannot be parameterized
    23Expression assertEquals(1,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    24Expression thing.setName("two") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Expression thing.setName("two") is a void method call, and thus it cannot be parameterized
    26Expression assertEquals(1,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    27Unmatched 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
    28Unmatched statement s.merge(thing); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    29Unmatched 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
    30Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    31Expression assertTrue(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    32Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    33Expression assertTrue(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    34Unmatched 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
    35Expression assertEquals("two",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    36Expression assertEquals("two",thing.getName()) is a void method call, and thus it cannot be parameterized
    37Expression gavin.getThings().clear() is a void method call, and thus it cannot be parameterized
    38Expression assertEquals("two",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    39Expression assertEquals("two",thing.getName()) is a void method call, and thus it cannot be parameterized
    40Expression gavin.getThings().clear() is a void method call, and thus it cannot be parameterized
    41Expression s.delete(thing) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    42Expression s.delete(thing) is a void method call, and thus it cannot be parameterized
    43Expression assertEquals(2,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    44Expression s.delete(thing) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    45Expression s.delete(thing) is a void method call, and thus it cannot be parameterized
    46Expression assertEquals(2,gavin.getVersion()) is a void method call, and thus it cannot be parameterized