Session s = openSession(); Transaction t = s.beginTransaction(); // create a new thing with a non-null name Thing thing = new Thing(); thing.setName("one"); 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); assertEquals("one", thing.getName()); t.commit(); s.close(); // change detached thing name to a new non-null name and save it thing.setName("one_changed"); 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("one_changed", 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 testUpdateNonNullOptionalJoinToDiffNonNullDetached() 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 non-null name
3
		
4
		Thing thing = new Thing();
5
		thing.setName("one");
6
		s.save(th
4
Person gavin = new Person("Gavin");
5
		new Thing("Passport", gavin);
7
ing);
6
		s.persist(gavin);
8
		t.commit();
7
		t.commit();
9
		s.close();
8
		s.close();
9
		
10
		assertEquals(0, gavin.getVersion());
11
		
10
		s = openSession();
12
		s = openSession();
11
		t = s.beginTransaction();
13
		t = s.beginTransaction();
12
		List things = s.createQuery("from Thing").list();
14
		
13
		assertEquals(1, things.size());
14
		thing = (Thing)things.get(0);
15
		assertEquals("one", thing.getName()
15
gavin = (Person) s.createCriteria(Person.class).uniqueResult();
16
);
16
		new Thing("Laptop", gavin);
17
		t.commit();
17
		t.commit();
18
		s.close();
18
		s.close();
19
				
19
		
20
		// change detached thing name to a new non-null name and save it
20
		
21
		thing.setName("one_changed");
22
		s = openSession();
23
		t = s.beginTransaction();
24
		s.update(thing
21
assertEquals(1, gavin.getVersion());
22
		assertFalse( Hibernate.isInitialized( gavin.getThings() ) );
23
		s = openSession();
24
		t = s.beginTransaction();
25
		gavin = (Person) s.createCriteria(Person.class).uniqueResult();
25
);
26
		gavin.getThings().clear();
26
		t.commit();
27
		t.commit();
27
		s.close();
28
		s.close();
29
		
28
		s = openSession();
30
		
29
		t = s.beginTransaction();
31
assertEquals(2, gavin.getVersion());
30
		things = s.createQuery("from Thing").list();
32
		
31
		assertEquals(1, things.size());
33
assertTrue( Hibernate.isInitialized( gavin.getThings() ) );
32
		thing = (Thing)things.get(0);
34
		
33
		assertEquals("one_changed", thing.getName()
35
s = openSession();
34
);
36
		t = s.beginTransaction();
35
		s.delete(thing);
37
		s.delete(gavin);
36
		t.commit();
38
		t.commit();
37
		s.close();
39
		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 statements24
    Number of unmapped statements in the first code fragment6
    Number of unmapped statements in the second code fragment5
    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("one");
    4
    thing.setName("one");
    8
    assertEquals(0, gavin.getVersion());
    Differences
    Expression1Expression2Difference
    setNameassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    thing.setName("one")assertEquals(0,gavin.getVersion())ARGUMENT_NUMBER_MISMATCH
    thingMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression thing.setName("one") 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 thing.setName("one") 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());
    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);
                                                                                                                                    
    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);
    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
    assertEquals("one", thing.getName());
    13
    assertEquals("one", thing.getName());
    16
    assertFalse(Hibernate.isInitialized(gavin.getThings()));
    Differences
    Expression1Expression2Difference
    assertEqualsassertFalseMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals("one",thing.getName())assertFalse(Hibernate.isInitialized(gavin.getThings()))ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals("one",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("one",thing.getName()) 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 assertEquals("one",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("one",thing.getName()) 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()));
    14
    t.commit();
    13
    t.commit();
    15
    s.close();
    14
    s.close();
    16
    thing.setName("one_changed");
    16
    thing.setName("one_changed");
    15
    assertEquals(1, gavin.getVersion());
    Differences
    Expression1Expression2Difference
    setNameassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    thing.setName("one_changed")assertEquals(1,gavin.getVersion())ARGUMENT_NUMBER_MISMATCH
    thingMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression thing.setName("one_changed") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression thing.setName("one_changed") 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("one_changed") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression thing.setName("one_changed") 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.update(thing);
    19
    s.update(thing);
    23
    assertEquals(2, gavin.getVersion());
    Differences
    Expression1Expression2Difference
    updateassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    s.update(thing)assertEquals(2,gavin.getVersion())ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.update(thing) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.update(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.update(thing) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.update(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());
    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("one_changed", thing.getName());
    27
    assertEquals("one_changed", thing.getName());
    20
    gavin.getThings().clear();
    Differences
    Expression1Expression2Difference
    assertEqualsclearMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals("one_changed",thing.getName())gavin.getThings().clear()ARGUMENT_NUMBER_MISMATCH
    gavin.getThings()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals("one_changed",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("one_changed",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("one_changed",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("one_changed",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);
    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 (46)
    Row Violation
    1Expression thing.setName("one") is a void method call, and thus it cannot be parameterized
    2Expression assertEquals(0,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    3Expression thing.setName("one") is a void method call, and thus it cannot be parameterized
    4Expression assertEquals(0,gavin.getVersion()) 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 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
    14Unmatched 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
    15Expression assertEquals("one",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Expression assertEquals("one",thing.getName()) is a void method call, and thus it cannot be parameterized
    17Expression assertFalse(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    18Expression assertEquals("one",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19Expression assertEquals("one",thing.getName()) is a void method call, and thus it cannot be parameterized
    20Expression assertFalse(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    21Expression thing.setName("one_changed") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression thing.setName("one_changed") 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("one_changed") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Expression thing.setName("one_changed") 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
    28Expression s.update(thing) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    29Expression s.update(thing) is a void method call, and thus it cannot be parameterized
    30Expression assertEquals(2,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    31Expression s.update(thing) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    32Expression s.update(thing) is a void method call, and thus it cannot be parameterized
    33Expression assertEquals(2,gavin.getVersion()) is a void method call, and thus it cannot be parameterized
    34Unmatched 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
    35Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    36Expression assertTrue(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    37Expression assertEquals(1,things.size()) is a void method call, and thus it cannot be parameterized
    38Expression assertTrue(Hibernate.isInitialized(gavin.getThings())) is a void method call, and thus it cannot be parameterized
    39Unmatched 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
    40Expression assertEquals("one_changed",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    41Expression assertEquals("one_changed",thing.getName()) is a void method call, and thus it cannot be parameterized
    42Expression gavin.getThings().clear() is a void method call, and thus it cannot be parameterized
    43Expression assertEquals("one_changed",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    44Expression assertEquals("one_changed",thing.getName()) is a void method call, and thus it cannot be parameterized
    45Expression gavin.getThings().clear() is a void method call, and thus it cannot be parameterized
    46Type org.hibernate.test.join.Thing of variable thing does not match with type org.hibernate.test.version.Person of variable gavin