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();
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.merge(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 testOrphanDeleteOnSaveOrUpdate() Method name: void testOrphanDeleteOnMerge()
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
		prod.getParts().remove( mapKey );
13
		session = openSession();
13
		session = openSession();
14
		t = session.beginTransaction();
14
		t = session.beginTransaction();
15
		session.saveOrUpdate(prod);
15
		session.merge(prod);
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();
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 comparisons140
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements23
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    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
    prod.getParts().remove(mapKey);
    12
    prod.getParts().remove(mapKey);
    13
    session = openSession();
    13
    session = openSession();
    14
    t = session.beginTransaction();
    14
    t = session.beginTransaction();
                                                    
    15
    session.merge(prod);
    Preondition Violations
    Unmatched statement session.merge(prod); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15
    session.merge(prod);
    15
    session.saveOrUpdate(prod);
    15
    session.saveOrUpdate(prod);
    Preondition Violations
    Unmatched statement session.saveOrUpdate(prod); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                  
    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 (3)
    Row Violation
    1Unmatched statement session.merge(prod); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement session.saveOrUpdate(prod); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Clone fragment #1 returns variables prod, session , while Clone fragment #2 returns variables prod, session