Session s = openSession(); s.beginTransaction(); Parent p = new Parent( "p" ); p.getChildren().add( new Child( "c" ) ); s.save( p ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); p = ( Parent ) s.get( Parent.class, "p" ); // clear... s.clear(); // now try to reattach... s.update( p ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); s.delete( p ); s.getTransaction().commit(); s.close();
Session s = openSession(); s.beginTransaction(); Parent p = new Parent( "p" ); p.getChildren().add( new Child( "c" ) ); s.save( p ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); p = ( Parent ) s.get( Parent.class, "p" ); // evict... s.evict( p ); // now try to reattach... s.update( p ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); s.delete( p ); s.getTransaction().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/reattachment/CollectionReattachmentTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/reattachment/CollectionReattachmentTest.java
Method name: void testUpdateOwnerAfterClear() Method name: void testUpdateOwnerAfterEvict()
Number of AST nodes: 19 Number of AST nodes: 19
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		s.beginTransaction();
3
		Parent p = new Parent( "p" );
3
		Parent p = new Parent( "p" );
4
		p.getChildren().add( new Child( "c" ) );
4
		p.getChildren().add( new Child( "c" ) );
5
		s.save( p );
5
		s.save( p );
6
		s.getTransaction().commit();
6
		s.getTransaction().commit();
7
		s.close();
7
		s.close();
8
		s = openSession();
8
		s = openSession();
9
		s.beginTransaction();
9
		s.beginTransaction();
10
		p = ( Parent ) s.get( Parent.class, "p" );
10
		p = ( Parent ) s.get( Parent.class, "p" );
11
		// clear...
11
		// evict...
12
		s.clear();
12
		s.evict( p );
13
		// now try to reattach...
13
		// now try to reattach...
14
		s.update( p );
14
		s.update( p );
15
		s.getTransaction().commit();
15
		s.getTransaction().commit();
16
		s.close();
16
		s.close();
17
		s = openSession();
17
		s = openSession();
18
		s.beginTransaction();
18
		s.beginTransaction();
19
		s.delete( p );
19
		s.delete( p );
20
		s.getTransaction().commit();
20
		s.getTransaction().commit();
21
		s.close();
21
		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 comparisons81
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements19
    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
    s.beginTransaction();
    2
    s.beginTransaction();
    3
    Parent p = new Parent("p");
    3
    Parent p = new Parent("p");
    4
    p.getChildren().add(new Child("c"));
    4
    p.getChildren().add(new Child("c"));
    5
    s.save(p);
    5
    s.save(p);
    6
    s.getTransaction().commit();
    6
    s.getTransaction().commit();
    7
    s.close();
    7
    s.close();
    8
    s = openSession();
    8
    s = openSession();
    9
    s.beginTransaction();
    9
    s.beginTransaction();
    10
    p = (Parent)s.get(Parent.class, "p");
    10
    p = (Parent)s.get(Parent.class, "p");
    11
    s.clear();
    11
    s.clear();
    12
    s.update(p);
    Differences
    Expression1Expression2Difference
    clearupdateMETHOD_INVOCATION_NAME_MISMATCH
    s.clear()s.update(p)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression s.clear() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.update(p) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.clear() is a void method call, and thus it cannot be parameterized
    Expression s.update(p) is a void method call, and thus it cannot be parameterized
    Expression s.clear() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.update(p) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.clear() is a void method call, and thus it cannot be parameterized
    Expression s.update(p) is a void method call, and thus it cannot be parameterized
    12
    s.update(p);
    12
    s.update(p);
    12
    s.update(p);
    11
    s.evict(p);
    Differences
    Expression1Expression2Difference
    updateevictMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression s.update(p) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.evict(p) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.update(p) is a void method call, and thus it cannot be parameterized
    Expression s.evict(p) is a void method call, and thus it cannot be parameterized
    11
    s.evict(p);
    13
    s.getTransaction().commit();
    13
    s.getTransaction().commit();
    14
    s.close();
    14
    s.close();
    15
    s = openSession();
    15
    s = openSession();
    16
    s.beginTransaction();
    16
    s.beginTransaction();
    17
    s.delete(p);
    17
    s.delete(p);
    18
    s.getTransaction().commit();
    18
    s.getTransaction().commit();
    19
    s.close();
    19
    s.close();
    Precondition Violations (12)
    Row Violation
    1Expression s.clear() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression s.update(p) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression s.clear() is a void method call, and thus it cannot be parameterized
    4Expression s.update(p) is a void method call, and thus it cannot be parameterized
    5Expression s.clear() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression s.update(p) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression s.clear() is a void method call, and thus it cannot be parameterized
    8Expression s.update(p) is a void method call, and thus it cannot be parameterized
    9Expression s.update(p) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression s.evict(p) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression s.update(p) is a void method call, and thus it cannot be parameterized
    12Expression s.evict(p) is a void method call, and thus it cannot be parameterized