Session s = openSession(); s.beginTransaction(); A a = new A(); a.setData( "Anna" ); s.save( a ); s.getTransaction().commit(); s.close(); // modify detached entity modifyEntity( a ); s = openSession(); s.beginTransaction(); a = ( A ) s.merge( a ); s.getTransaction().commit(); s.close(); verifyModifications( a.getId() ); // add a new (transient) G to collection in h // there is no cascade from H to the collection, so this should fail when merged assertEquals( 1, a.getHs().size() ); H h = ( H ) a.getHs().iterator().next(); G gNew = new G(); gNew.setData( "Gail" ); gNew.getHs().add( h ); h.getGs().add( gNew ); s = openSession(); s.beginTransaction(); try { s.merge( a ); s.merge( h ); fail( "should have thrown TransientObjectException" ); } catch ( TransientObjectException ex ) { // expected } finally { s.getTransaction().rollback(); } s.close();
Session s = openSession(); s.beginTransaction(); A a = new A(); a.setData( "Anna" ); s.save( a ); s.getTransaction().commit(); s.close(); // modify detached entity modifyEntity( a ); s = openSession(); s.beginTransaction(); a = ( A ) s.merge( a ); s.getTransaction().commit(); s.close(); verifyModifications( a.getId() ); // change the many-to-one association from h to be a new (transient) A // there is no cascade from H to A, so this should fail when merged assertEquals( 1, a.getHs().size() ); H h = ( H ) a.getHs().iterator().next(); a.getHs().remove( h ); A aNew = new A(); aNew.setData( "Alice" ); aNew.addH( h ); s = openSession(); s.beginTransaction(); try { s.merge( a ); s.merge( h ); fail( "should have thrown TransientObjectException" ); } catch ( TransientObjectException ex ) { // expected } finally { s.getTransaction().rollback(); } 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/cascade/MultiPathCascadeTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/cascade/MultiPathCascadeTest.java
Method name: void testMultiPathMergeNonCascadedTransientEntityInCollection() Method name: void testMultiPathMergeNonCascadedTransientEntityInManyToOne()
Number of AST nodes: 27 Number of AST nodes: 27
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		s.beginTransaction();
3
		A a = new A();
3
		A a = new A();
4
		a.setData( "Anna" );
4
		a.setData( "Anna" );
5
		s.save( a );
5
		s.save( a );
6
		s.getTransaction().commit();
6
		s.getTransaction().commit();
7
		s.close();
7
		s.close();
8
		// modify detached entity
8
		// modify detached entity
9
		modifyEntity( a );
9
		modifyEntity( a );
10
		s = openSession();
10
		s = openSession();
11
		s.beginTransaction();
11
		s.beginTransaction();
12
		a = ( A ) s.merge( a );
12
		a = ( A ) s.merge( a );
13
		s.getTransaction().commit();
13
		s.getTransaction().commit();
14
		s.close();
14
		s.close();
15
		verifyModifications( a.getId() );
15
		verifyModifications( a.getId() );
16
		// add a new (transient) G to collection in h
16
		// change the many-to-one association from h to be a new (transient) A
17
		// there is no cascade from H to the collection, so this should fail when merged
17
		// there is no cascade from H to A, so this should fail when merged
18
		assertEquals( 1, a.getHs().size() );
18
		assertEquals( 1, a.getHs().size() );
19
		H h = ( H ) a.getHs().iterator().next();
19
		H h = ( H ) a.getHs().iterator().next();
20
		G g
20
		a.getHs().remove( h );
21
New = new G();
21
		A aNew = new A();
22
		gNew.setData( "Gail" );
22
		aNew.setData( "Alice" );
23
		gNew.getHs().add( h );
23
		aNew.addH( h );
24
		h.getGs().add( gNew );
25
		s = openSession();
24
		s = openSession();
26
		s.beginTransaction();
25
		s.beginTransaction();
27
		try {
26
		try {
28
			s.merge( a );
27
			s.merge( a );
29
			s.merge( h );
28
			s.merge( h );
30
			fail( "should have thrown TransientObjectException" );
29
			fail( "should have thrown TransientObjectException" );
31
		}
30
		}
32
		catch ( TransientObjectException ex ) {
31
		catch ( TransientObjectException ex ) {
33
			// expected
32
			// expected
34
		}
33
		}
35
		finally {
34
		finally {
36
			s.getTransaction().rollback();
35
			s.getTransaction().rollback();
37
		}
36
		}
38
		s.close();
37
		s.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.2
Clones locationClones are declared in the same class
Number of node comparisons143
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements24
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)39.1
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
    2
    s.beginTransaction();
    2
    s.beginTransaction();
    3
    A a = new A();
    3
    A a = new A();
    4
    a.setData("Anna");
    4
    a.setData("Anna");
    5
    s.save(a);
    5
    s.save(a);
    6
    s.getTransaction().commit();
    6
    s.getTransaction().commit();
    7
    s.close();
    7
    s.close();
    8
    modifyEntity(a);
    8
    modifyEntity(a);
    9
    s = openSession();
    9
    s = openSession();
    10
    s.beginTransaction();
    10
    s.beginTransaction();
    11
    a = (A)s.merge(a);
    11
    a = (A)s.merge(a);
    12
    s.getTransaction().commit();
    12
    s.getTransaction().commit();
    13
    s.close();
    13
    s.close();
    14
    verifyModifications(a.getId());
    14
    verifyModifications(a.getId());
    15
    assertEquals(1, a.getHs().size());
    15
    assertEquals(1, a.getHs().size());
    16
    H h = (H)a.getHs().iterator().next();
    16
    H h = (H)a.getHs().iterator().next();
                                                    
    17
    a.getHs().remove(h);
    Preondition Violations
    Unmatched statement a.getHs().remove(h); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17
    a.getHs().remove(h);
    17
    G gNew = new G();
    17
    G gNew = new G();
    Preondition Violations
    Unmatched statement G gNew=new G(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                          
                                          
    18
    A aNew = new A();
    Preondition Violations
    Unmatched statement A aNew=new A(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    18
    A aNew = new A();
    18
    gNew.setData("Gail");
    18
    gNew.setData("Gail");
    19
    aNew.setData("Alice");
    Differences
    Expression1Expression2Difference
    "Gail""Alice"LITERAL_VALUE_MISMATCH
    gNewaNewVARIABLE_NAME_MISMATCH
    org.hibernate.test.cascade.Gorg.hibernate.test.cascade.AVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cascade.G of variable gNew does not match with type org.hibernate.test.cascade.A of variable aNew
    • Make classes org.hibernate.test.cascade.G and org.hibernate.test.cascade.A extend a common superclass
    19
    aNew.setData("Alice");
    19
    gNew.getHs().add(h);
    19
    gNew.getHs().add(h);
    Preondition Violations
    Unmatched statement gNew.getHs().add(h); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                    
                                      
    20
    aNew.addH(h);
    Preondition Violations
    Unmatched statement aNew.addH(h); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    20
    aNew.addH(h);
    20
    h.getGs().add(gNew);
    20
    h.getGs().add(gNew);
    Preondition Violations
    Unmatched statement h.getGs().add(gNew); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                    
    21
    s = openSession();
    21
    s = openSession();
    22
    s.beginTransaction();
    22
    s.beginTransaction();
    23
    try
    23
    try
    24
    s.merge(a);
    24
    s.merge(a);
    25
    s.merge(h);
    25
    s.merge(h);
    26
    fail("should have thrown TransientObjectException");
    26
    fail("should have thrown TransientObjectException");
    27
    s.close();
    27
    s.close();
    Precondition Violations (8)
    Row Violation
    1Unmatched statement a.getHs().remove(h); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement G gNew=new G(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement A aNew=new A(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Type org.hibernate.test.cascade.G of variable gNew does not match with type org.hibernate.test.cascade.A of variable aNew
    5Unmatched statement gNew.getHs().add(h); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement aNew.addH(h); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched statement h.getGs().add(gNew); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Clone fragment #1 returns variables h , while Clone fragment #2 returns variables a, h