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.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("one_changed", thing.getName()); s.delete(thing); t.commit(); s.close();
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();
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 testMergeNonNullOptionalJoinToDiffNonNullDetached() Method name: void testMergeNullOptionalJoinToNonNullDetached()
Number of AST nodes: 30 Number of AST nodes: 30
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
		// create a new thing with a null name
4
		Thing thing = new Thing();
4
		Thing thing = new Thing();
5
		thing.setName("one");
5
		thing.setName(null);
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
		assertEquals("one", thing.getName());
14
		assertNull(thing.getName());
15
		t.commit();
15
		t.commit();
16
		s.close();
16
		s.close();
17
		// change detached thing name to a new non-null name and save it
17
		// change detached thing name to a non-null value
18
		thing.setName("one_changed");
18
		thing.setName("two");
19
		s = openSession();
19
		s = openSession();
20
		t = s.beginTransaction();
20
		t = s.beginTransaction();
21
		s.merge(thing);
21
		s.merge(thing);
22
		t.commit();
22
		t.commit();
23
		s.close();
23
		s.close();
24
		s = openSession();
24
		s = openSession();
25
		t = s.beginTransaction();
25
		t = s.beginTransaction();
26
		things = s.createQuery("from Thing").list();
26
		things = s.createQuery("from Thing").list();
27
		assertEquals(1, things.size());
27
		assertEquals(1, things.size());
28
		thing = (Thing)things.get(0);
28
		thing = ((Thing) things.get(0));
29
		assertEquals("one_changed", thing.getName());
29
		assertEquals("two", thing.getName());
30
		s.delete(thing);
30
		s.delete(thing);
31
		t.commit();
31
		t.commit();
32
		s.close();
32
		s.close();
Summary
Number of common nesting structure subtrees1
Number of refactorable cases1
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones locationClones are declared in the same class
Number of node comparisons187
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements30
    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("one");
    4
    thing.setName("one");
    4
    thing.setName(null);
    Differences
    Expression1Expression2Difference
    "one"nullTYPE_COMPATIBLE_REPLACEMENT
    4
    thing.setName(null);
    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
    assertEquals("one", thing.getName());
    13
    assertEquals("one", thing.getName());
    13
    assertNull(thing.getName());
    Differences
    Expression1Expression2Difference
    assertEqualsassertNullMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals("one",thing.getName())assertNull(thing.getName())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 assertNull(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 assertNull(thing.getName()) 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 assertNull(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 assertNull(thing.getName()) is a void method call, and thus it cannot be parameterized
    13
    assertNull(thing.getName());
    14
    t.commit();
    14
    t.commit();
    15
    s.close();
    15
    s.close();
    16
    thing.setName("one_changed");
    16
    thing.setName("one_changed");
    16
    thing.setName("two");
    Differences
    Expression1Expression2Difference
    "one_changed""two"LITERAL_VALUE_MISMATCH
    16
    thing.setName("two");
    17
    s = openSession();
    17
    s = openSession();
    18
    t = s.beginTransaction();
    18
    t = s.beginTransaction();
    19
    s.merge(thing);
    19
    s.merge(thing);
    20
    t.commit();
    20
    t.commit();
    21
    s.close();
    21
    s.close();
    22
    s = openSession();
    22
    s = openSession();
    23
    t = s.beginTransaction();
    23
    t = s.beginTransaction();
    24
    things = s.createQuery("from Thing").list();
    24
    things = s.createQuery("from Thing").list();
    25
    assertEquals(1, things.size());
    25
    assertEquals(1, things.size());
    26
    thing = (Thing)things.get(0);
    26
    thing = (Thing)things.get(0);
    26
    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
    26
    thing = ((Thing)things.get(0));
    27
    assertEquals("one_changed", thing.getName());
    27
    assertEquals("one_changed", thing.getName());
    27
    assertEquals("two", thing.getName());
    Differences
    Expression1Expression2Difference
    "one_changed""two"LITERAL_VALUE_MISMATCH
    27
    assertEquals("two", thing.getName());
    28
    s.delete(thing);
    28
    s.delete(thing);
    29
    t.commit();
    29
    t.commit();
    30
    s.close();
    30
    s.close();
    Precondition Violations (10)
    Row Violation
    1Expression assertEquals("one",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression assertNull(thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression assertEquals("one",thing.getName()) is a void method call, and thus it cannot be parameterized
    4Expression assertNull(thing.getName()) is a void method call, and thus it cannot be parameterized
    5Expression assertEquals("one",thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression assertNull(thing.getName()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression assertEquals("one",thing.getName()) is a void method call, and thus it cannot be parameterized
    8Expression assertNull(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