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 ); prod = (Product) SerializationHelper.clone( prod ); 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(); 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();
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 testOrphanDeleteOnSaveOrUpdateAfterSerialization() Method name: void testOrphanDeleteAfterLock()
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( "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 );
13
		prod = (Product) SerializationHelper.clone( prod );
14
		session = openSession();
12
		session = openSession();
15
		t = session.beginTransaction();
13
		t = session.beginTransaction();
16
		session.saveOrUpdate(prod
14
		session.lock(prod, LockMode.READ);
17
);
15
		prod.getParts().remove(mapKey);
18
		t.commit();
16
		t.commit();
19
		session.close();
17
		session.close();
20
		session = openSession();
18
		session = openSession();
21
		t = session.beginTransaction();
19
		t = session.beginTransaction();
22
		assertNull( session.get(Part.class, "Widge") );
20
		assertNull( session.get(Part.class, "Widge") );
23
		assertNotNull( session.get(Part.class, "Get") );
21
		assertNotNull( session.get(Part.class, "Get") );
24
		session.delete( session.get(Product.class, "Widget") );
22
		session.delete( session.get(Product.class, "Widget") );
25
		t.commit();
23
		t.commit();
26
		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 comparisons149
  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("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);
    15
    prod.getParts().remove(mapKey);
    13
    prod = (Product)SerializationHelper.clone(prod);
    13
    prod = (Product)SerializationHelper.clone(prod);
    Preondition Violations
    Unmatched statement prod=(Product)SerializationHelper.clone(prod); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                        
    14
    session = openSession();
    12
    session = openSession();
    15
    t = session.beginTransaction();
    13
    t = session.beginTransaction();
    16
    session.saveOrUpdate(prod);
    16
    session.saveOrUpdate(prod);
    14
    session.lock(prod, LockMode.READ);
    Differences
    Expression1Expression2Difference
    saveOrUpdatelockMETHOD_INVOCATION_NAME_MISMATCH
    session.saveOrUpdate(prod)session.lock(prod,LockMode.READ)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression session.saveOrUpdate(prod) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.lock(prod,LockMode.READ) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.saveOrUpdate(prod) is a void method call, and thus it cannot be parameterized
    Expression session.lock(prod,LockMode.READ) is a void method call, and thus it cannot be parameterized
    Expression session.saveOrUpdate(prod) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.lock(prod,LockMode.READ) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.saveOrUpdate(prod) is a void method call, and thus it cannot be parameterized
    Expression session.lock(prod,LockMode.READ) is a void method call, and thus it cannot be parameterized
    14
    session.lock(prod, LockMode.READ);
    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
    assertNotNull(session.get(Part.class, "Get"));
    21
    assertNotNull(session.get(Part.class, "Get"));
    23
    session.delete(session.get(Product.class, "Widget"));
    22
    session.delete(session.get(Product.class, "Widget"));
    24
    t.commit();
    23
    t.commit();
    25
    session.close();
    24
    session.close();
    Precondition Violations (10)
    Row Violation
    1Unmatched statement prod=(Product)SerializationHelper.clone(prod); cannot be moved before or after the extracted code, 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) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression session.saveOrUpdate(prod) is a void method call, and thus it cannot be parameterized
    5Expression session.lock(prod,LockMode.READ) is a void method call, and thus it cannot be parameterized
    6Expression session.saveOrUpdate(prod) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression session.lock(prod,LockMode.READ) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression session.saveOrUpdate(prod) is a void method call, and thus it cannot be parameterized
    9Expression session.lock(prod,LockMode.READ) is a void method call, and thus it cannot be parameterized
    10Clone fragment #1 returns variables prod , while Clone fragment #2 returns variables