Session session = openSession(); Transaction t = session.beginTransaction(); Product prod = new Product(); prod.setName("Widget"); Part part = new Part(); part.setName("Widge"); part.setDescription("part if a Widget"); prod.getParts().add(part); Part part2 = new Part(); part2.setName("Get"); part2.setDescription("another part if a Widget"); prod.getParts().add(part2); session.persist(prod); session.flush(); prod.getParts().remove(part); session.delete(prod); t.commit(); session.close(); session = openSession(); t = session.beginTransaction(); assertNull( session.get(Part.class, "Widge") ); assertNull( session.get(Part.class, "Get") ); assertNull( session.get(Product.class, "Widget") ); t.commit(); session.close();
Session session = openSession(); Transaction t = session.beginTransaction(); Product prod = new Product(); prod.setName("Widget"); Part part = new Part(); part.setName("Widge"); part.setDescription("part if a Widget"); prod.getParts().add(part); Part part2 = new Part(); part2.setName("Get"); part2.setDescription("another part if a Widget"); prod.getParts().add(part2); session.persist(prod); session.flush(); prod.getParts().remove(part); t.commit(); session.close(); session = openSession(); t = session.beginTransaction(); assertNull( session.get(Part.class, "Widge") ); assertNotNull( session.get(Part.class, "Get") ); session.delete( session.get(Product.class, "Widget") ); t.commit(); session.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/orphan/OrphanTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/orphan/OrphanTest.java
Method name: void testOrphanDeleteOnDelete() Method name: void testOrphanDeleteAfterPersistAndFlush()
Number of AST nodes: 25 Number of AST nodes: 24
1
Session session = openSession();
1
Session session = openSession();
2
		Transaction t = session.beginTransaction();
2
		Transaction t = session.beginTransaction();
3
		Product prod = new Product();
3
		Product prod = new Product();
4
		prod.setName("Widget");
4
		prod.setName("Widget");
5
		Part part = new Part();
5
		Part part = new Part();
6
		part.setName("Widge");
6
		part.setName("Widge");
7
		part.setDescription("part if a Widget");
7
		part.setDescription("part if a Widget");
8
		prod.getParts().add(part);
8
		prod.getParts().add(part);
9
		Part part2 = new Part();
9
		Part part2 = new Part();
10
		part2.setName("Get");
10
		part2.setName("Get");
11
		part2.setDescription("another part if a Widget");
11
		part2.setDescription("another part if a Widget");
12
		prod.getParts().add(part2);
12
		prod.getParts().add(part2);
13
		session.persist(prod);
13
		session.persist(prod);
14
		session.flush();
14
		session.flush();
15
		
15
		
16
		prod.getParts().remove(part);
16
		prod.getParts().remove(part);
17
		
17
		
18
		session.delete(prod);
18
		
19
		
20
		t.commit();
19
t.commit();
21
		session.close();
20
		session.close();
22
		
21
		
23
		session = openSession();
22
		session = openSession();
24
		t = session.beginTransaction();
23
		t = session.beginTransaction();
25
		assertNull( session.get(Part.class, "Widge") );
24
		assertNull( session.get(Part.class, "Widge") );
26
		assertNull( session.get(Part.class, "Get") );
25
		assertNotNull( session.get(Part.class, "Get") );
27
		assertNull( session.get(Product.class, "Widget") );
26
		session.delete( session.get(Product.class, "Widget") );
28
		t.commit();
27
		t.commit();
29
		session.close();
28
		session.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 comparisons212
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements24
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    Session session = openSession();
    1
    Session session = openSession();
    2
    Transaction t = session.beginTransaction();
    2
    Transaction t = session.beginTransaction();
    3
    Product prod = new Product();
    3
    Product prod = new Product();
    4
    prod.setName("Widget");
    4
    prod.setName("Widget");
    5
    Part part = new Part();
    5
    Part part = new Part();
    6
    part.setName("Widge");
    6
    part.setName("Widge");
    7
    part.setDescription("part if a Widget");
    7
    part.setDescription("part if a Widget");
    8
    prod.getParts().add(part);
    8
    prod.getParts().add(part);
    9
    Part part2 = new Part();
    9
    Part part2 = new Part();
    10
    part2.setName("Get");
    10
    part2.setName("Get");
    11
    part2.setDescription("another part if a Widget");
    11
    part2.setDescription("another part if a Widget");
    12
    prod.getParts().add(part2);
    12
    prod.getParts().add(part2);
    13
    session.persist(prod);
    13
    session.persist(prod);
    14
    session.flush();
    14
    session.flush();
    15
    prod.getParts().remove(part);
    15
    prod.getParts().remove(part);
    16
    session.delete(prod);
    16
    session.delete(prod);
    Preondition Violations
    Unmatched statement session.delete(prod); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                      
    17
    t.commit();
    16
    t.commit();
    18
    session.close();
    17
    session.close();
    19
    session = openSession();
    18
    session = openSession();
    20
    t = session.beginTransaction();
    19
    t = session.beginTransaction();
    21
    assertNull(session.get(Part.class, "Widge"));
    20
    assertNull(session.get(Part.class, "Widge"));
    22
    assertNull(session.get(Part.class, "Get"));
    22
    assertNull(session.get(Part.class, "Get"));
    22
    session.delete(session.get(Product.class, "Widget"));
    Differences
    Expression1Expression2Difference
    assertNulldeleteMETHOD_INVOCATION_NAME_MISMATCH
    sessionMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertNull(session.get(Part.class,"Get")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.delete(session.get(Product.class,"Widget")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(session.get(Part.class,"Get")) is a void method call, and thus it cannot be parameterized
    Expression session.delete(session.get(Product.class,"Widget")) is a void method call, and thus it cannot be parameterized
    Expression assertNull(session.get(Part.class,"Get")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.delete(session.get(Product.class,"Widget")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(session.get(Part.class,"Get")) is a void method call, and thus it cannot be parameterized
    Expression session.delete(session.get(Product.class,"Widget")) is a void method call, and thus it cannot be parameterized
    22
    session.delete(session.get(Product.class, "Widget"));
    23
    assertNull(session.get(Product.class, "Widget"));
    23
    assertNull(session.get(Product.class, "Widget"));
    21
    assertNotNull(session.get(Part.class, "Get"));
    Differences
    Expression1Expression2Difference
    assertNullassertNotNullMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression assertNull(session.get(Product.class,"Widget")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNotNull(session.get(Part.class,"Get")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(session.get(Product.class,"Widget")) is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(session.get(Part.class,"Get")) is a void method call, and thus it cannot be parameterized
    21
    assertNotNull(session.get(Part.class, "Get"));
    24
    t.commit();
    23
    t.commit();
    25
    session.close();
    24
    session.close();
    Precondition Violations (14)
    Row Violation
    1Unmatched statement session.delete(prod); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Expression assertNull(session.get(Part.class,"Get")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression session.delete(session.get(Product.class,"Widget")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression assertNull(session.get(Part.class,"Get")) is a void method call, and thus it cannot be parameterized
    5Expression session.delete(session.get(Product.class,"Widget")) is a void method call, and thus it cannot be parameterized
    6Expression assertNull(session.get(Part.class,"Get")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression session.delete(session.get(Product.class,"Widget")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression assertNull(session.get(Part.class,"Get")) is a void method call, and thus it cannot be parameterized
    9Expression session.delete(session.get(Product.class,"Widget")) is a void method call, and thus it cannot be parameterized
    10Expression assertNull(session.get(Product.class,"Widget")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression assertNotNull(session.get(Part.class,"Get")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression assertNull(session.get(Product.class,"Widget")) is a void method call, and thus it cannot be parameterized
    13Expression assertNotNull(session.get(Part.class,"Get")) is a void method call, and thus it cannot be parameterized
    14Clone fragment #1 returns variables session, prod , while Clone fragment #2 returns variables