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()); // change name to a non-null value thing.setName("two"); 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(); // 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()); // give it a new non-null name and save it thing.setName("one_changed"); 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();
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/join/OptionalJoinTest.java
Method name: void testUpdateNullOptionalJoinToNonNull() Method name: void testUpdateNonNullOptionalJoinToDiffNonNull()
Number of AST nodes: 26 Number of AST nodes: 26
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
		// create a new thing with a non-null name
4
		Thing thing = new Thing();
4
		Thing thing = new Thing();
5
		thing.setName(null);
5
		thing.setName("one");
6
		s.save(thing);
6
		s.save(thing);
7
		t.commit();
7
		t.commit();
8
		s.close();
8
		s.close();
9
		s = openSession();
9
		s = openSession();
10
		t = s.beginTransaction();
10
		t = s.beginTransaction();
11
		List things = s.createQuery("from Thing").list();
11
		List things = s.createQuery("from Thing").list();
12
		assertEquals(1, things.size());
12
		assertEquals(1, things.size());
13
		thing = (Thing)things.get(0);
13
		thing = (Thing)things.get(0);
14
		assertNull(thing.getName());
14
		assertEquals("one", thing.getName());
15
		// change name to a non-null value
15
		// give it a new non-null name and save it
16
		thing.setName("two");
16
		thing.setName("one_changed");
17
		s.update(thing);
17
		s.update(thing);
18
		t.commit();
18
		t.commit();
19
		s.close();
19
		s.close();
20
		s = openSession();
20
		s = openSession();
21
		t = s.beginTransaction();
21
		t = s.beginTransaction();
22
		things = s.createQuery("from Thing").list();
22
		things = s.createQuery("from Thing").list();
23
		assertEquals(1, things.size());
23
		assertEquals(1, things.size());
24
		thing = ((Thing) things.get(0));
24
		thing = (Thing)things.get(0);
25
		assertEquals("two", thing.getName());
25
		assertEquals("one_changed", thing.getName());
26
		s.delete(thing);
26
		s.delete(thing);
27
		t.commit();
27
		t.commit();
28
		s.close();
28
		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 declared in the same class
Number of node comparisons158
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements26
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    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
    Thing thing = new Thing();
    3
    Thing thing = new Thing();
    4
    thing.setName(null);
    4
    thing.setName(null);
    4
    thing.setName("one");
    Differences
    Expression1Expression2Difference
    null"one"TYPE_COMPATIBLE_REPLACEMENT
    4
    thing.setName("one");
    5
    s.save(thing);
    5
    s.save(thing);
    6
    t.commit();
    6
    t.commit();
    7
    s.close();
    7
    s.close();
    8
    s = openSession();
    8
    s = openSession();
    9
    t = s.beginTransaction();
    9
    t = s.beginTransaction();
    10
    List things = s.createQuery("from Thing").list();
    10
    List things = s.createQuery("from Thing").list();
    11
    assertEquals(1, things.size());
    11
    assertEquals(1, things.size());
    12
    thing = (Thing)things.get(0);
    12
    thing = (Thing)things.get(0);
    13
    assertNull(thing.getName());
    13
    assertNull(thing.getName());
    13
    assertEquals("one", thing.getName());
    Differences
    Expression1Expression2Difference
    assertNullassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    assertNull(thing.getName())assertEquals("one",thing.getName())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("one",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("one",thing.getName()) 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("one",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("one",thing.getName()) is a void method call, and thus it cannot be parameterized
    13
    assertEquals("one", thing.getName());
    14
    thing.setName("two");
    14
    thing.setName("two");
    14
    thing.setName("one_changed");
    Differences
    Expression1Expression2Difference
    "two""one_changed"LITERAL_VALUE_MISMATCH
    14
    thing.setName("one_changed");
    15
    s.update(thing);
    15
    s.update(thing);
    16
    t.commit();
    16
    t.commit();
    17
    s.close();
    17
    s.close();
    18
    s = openSession();
    18
    s = openSession();
    19
    t = s.beginTransaction();
    19
    t = s.beginTransaction();
    20
    things = s.createQuery("from Thing").list();
    20
    things = s.createQuery("from Thing").list();
    21
    assertEquals(1, things.size());
    21
    assertEquals(1, things.size());
    22
    thing = ((Thing)things.get(0));
    22
    thing = ((Thing)things.get(0));
    22
    thing = (Thing)things.get(0);
    Differences
    Expression1Expression2Difference
    ((Thing)things.get(0))(Thing)things.get(0)TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression ((Thing)things.get(0)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression (Thing)things.get(0) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22
    thing = (Thing)things.get(0);
    23
    assertEquals("two", thing.getName());
    23
    assertEquals("two", thing.getName());
    23
    assertEquals("one_changed", thing.getName());
    Differences
    Expression1Expression2Difference
    "two""one_changed"LITERAL_VALUE_MISMATCH
    23
    assertEquals("one_changed", thing.getName());
    24
    s.delete(thing);
    24
    s.delete(thing);
    25
    t.commit();
    25
    t.commit();
    26
    s.close();
    26
    s.close();
    Precondition Violations (10)
    Row Violation
    1Expression assertNull(thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression assertEquals("one",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression assertNull(thing.getName()) is a void method call, and thus it cannot be parameterized
    4Expression assertEquals("one",thing.getName()) is a void method call, and thus it cannot be parameterized
    5Expression assertNull(thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression assertEquals("one",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression assertNull(thing.getName()) is a void method call, and thus it cannot be parameterized
    8Expression assertEquals("one",thing.getName()) is a void method call, and thus it cannot be parameterized
    9Expression ((Thing)things.get(0)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression (Thing)things.get(0) cannot be parameterized, because it has dependencies to/from statements that will be extracted