Session session = openSession(); Transaction t = session.beginTransaction(); Product prod = new Product( "Widget" ); Part part = new Part( "Widge", "part if a Widget" ); MapKey mapKey = new MapKey( "Top" ); prod.getParts().put( mapKey, part ); Part part2 = new Part( "Get", "another part if a Widget" ); prod.getParts().put( new MapKey( "Bottom" ),part2 ); session.persist( prod ); t.commit(); session.close(); session = openSession(); t = session.beginTransaction(); session.lock(prod, LockMode.READ); prod.getParts().remove(mapKey); 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();
Session session = openSession(); Transaction t = session.beginTransaction(); Product prod = new Product( "Widget" ); Part part = new Part( "Widge", "part if a Widget" ); MapKey mapKey = new MapKey( "Top" ); prod.getParts().put( mapKey, part ); Part part2 = new Part( "Get", "another part if a Widget" ); prod.getParts().put( new MapKey( "Bottom" ), part2 ); session.persist( prod ); t.commit(); session.close(); prod.getParts().remove( mapKey ); session = openSession(); t = session.beginTransaction(); session.saveOrUpdate(prod); 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/collection/backref/map/compkey/BackrefCompositeMapKeyTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/collection/backref/map/compkey/BackrefCompositeMapKeyTest.java
Method name: void testOrphanDeleteAfterLock() Method name: void testOrphanDeleteOnSaveOrUpdate()
Number of AST nodes: 24 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( "Widget" );
3
		Product prod = new Product( "Widget" );
4
		Part part = new Part( "Widge", "part if a Widget" );
4
		Part part = new Part( "Widge", "part if a Widget" );
5
		MapKey mapKey = new MapKey( "Top" );
5
		MapKey mapKey = new MapKey( "Top" );
6
		prod.getParts().put( mapKey, part );
6
		prod.getParts().put( mapKey, part );
7
		Part part2 = new Part( "Get", "another part if a Widget" );
7
		Part part2 = new Part( "Get", "another part if a Widget" );
8
		prod.getParts().put( new MapKey( "Bottom" ),part2 );
8
		prod.getParts().put( new MapKey( "Bottom" ), part2 );
9
		session.persist( prod );
9
		session.persist( prod );
10
		t.commit();
10
		t.commit();
11
		session.close();
11
		session.close();
12
		prod.getParts().remove( mapKey );
12
		session = openSession();
13
		session = openSession();
13
		t = session.beginTransaction();
14
		t = session.beginTransaction();
14
		session.lock(prod, LockMode.READ);
15
		session.
15
		prod.getParts().remove(mapKey);
16
saveOrUpdate(prod);
16
		t.commit();
17
		t.commit();
17
		session.close();
18
		session.close();
18
		session = openSession();
19
		session = openSession();
19
		t = session.beginTransaction();
20
		t = session.beginTransaction();
20
		assertNull( session.get(Part.class, "Widge") );
21
		assertNull( session.get(Part.class, "Widge") );
21
		assertNotNull( session.get(Part.class, "Get") );
22
		assertNotNull( session.get(Part.class, "Get") );
22
		session.delete( session.get(Product.class, "Widget") );
23
		session.delete( session.get(Product.class, "Widget") );
23
		t.commit();
24
		t.commit();
24
		session.close();
25
		session.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 comparisons140
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements24
    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 session = openSession();
    1
    Session session = openSession();
    2
    Transaction t = session.beginTransaction();
    2
    Transaction t = session.beginTransaction();
    3
    Product prod = new Product("Widget");
    3
    Product prod = new Product("Widget");
    4
    Part part = new Part("Widge", "part if a Widget");
    4
    Part part = new Part("Widge", "part if a Widget");
    5
    MapKey mapKey = new MapKey("Top");
    5
    MapKey mapKey = new MapKey("Top");
    6
    prod.getParts().put(mapKey, part);
    6
    prod.getParts().put(mapKey, part);
    7
    Part part2 = new Part("Get", "another part if a Widget");
    7
    Part part2 = new Part("Get", "another part if a Widget");
    8
    prod.getParts().put(new MapKey("Bottom"), part2);
    8
    prod.getParts().put(new MapKey("Bottom"), part2);
    9
    session.persist(prod);
    9
    session.persist(prod);
    10
    t.commit();
    10
    t.commit();
    11
    session.close();
    11
    session.close();
    12
    session = openSession();
    13
    session = openSession();
    13
    t = session.beginTransaction();
    14
    t = session.beginTransaction();
    14
    session.lock(prod, LockMode.READ);
    14
    session.lock(prod, LockMode.READ);
    15
    session.saveOrUpdate(prod);
    Differences
    Expression1Expression2Difference
    locksaveOrUpdateMETHOD_INVOCATION_NAME_MISMATCH
    session.lock(prod,LockMode.READ)session.saveOrUpdate(prod)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression session.lock(prod,LockMode.READ) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.saveOrUpdate(prod) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.lock(prod,LockMode.READ) is a void method call, and thus it cannot be parameterized
    Expression session.saveOrUpdate(prod) is a void method call, and thus it cannot be parameterized
    Expression session.lock(prod,LockMode.READ) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.saveOrUpdate(prod) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.lock(prod,LockMode.READ) is a void method call, and thus it cannot be parameterized
    Expression session.saveOrUpdate(prod) is a void method call, and thus it cannot be parameterized
    15
    session.saveOrUpdate(prod);
    15
    prod.getParts().remove(mapKey);
    12
    prod.getParts().remove(mapKey);
    16
    t.commit();
    16
    t.commit();
    17
    session.close();
    17
    session.close();
    18
    session = openSession();
    18
    session = openSession();
    19
    t = session.beginTransaction();
    19
    t = session.beginTransaction();
    20
    assertNull(session.get(Part.class, "Widge"));
    20
    assertNull(session.get(Part.class, "Widge"));
    21
    assertNotNull(session.get(Part.class, "Get"));
    21
    assertNotNull(session.get(Part.class, "Get"));
    22
    session.delete(session.get(Product.class, "Widget"));
    22
    session.delete(session.get(Product.class, "Widget"));
    23
    t.commit();
    23
    t.commit();
    24
    session.close();
    24
    session.close();
    Precondition Violations (8)
    Row Violation
    1Expression session.lock(prod,LockMode.READ) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression session.saveOrUpdate(prod) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression session.lock(prod,LockMode.READ) is a void method call, and thus it cannot be parameterized
    4Expression session.saveOrUpdate(prod) is a void method call, and thus it cannot be parameterized
    5Expression session.lock(prod,LockMode.READ) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression session.saveOrUpdate(prod) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression session.lock(prod,LockMode.READ) is a void method call, and thus it cannot be parameterized
    8Expression session.saveOrUpdate(prod) is a void method call, and thus it cannot be parameterized