try { Session s = openSession(); s.beginTransaction(); ParentAssigned p = new ParentAssigned( new Long( 1 ), "parent" ); ParentInfoAssigned info = new ParentInfoAssigned( "something secret" ); p.setInfo( info ); info.setOwner( p ); s.persist( p ); try { s.getTransaction().commit(); fail( "expecting TransientObjectException on flush" ); } catch( TransientObjectException e ) { // expected result log.trace( "handled expected exception", e ); s.getTransaction().rollback(); } finally { s.close(); } } finally { cleanupData(); }
try { Session s = openSession(); s.beginTransaction(); ParentAssigned p = new ParentAssigned( new Long( 1 ), "parent" ); OtherAssigned other = new OtherAssigned( new Long( 2 ) ); other.setOwner( p ); s.persist( other ); try { s.getTransaction().commit(); fail( "expecting TransientObjectException on flush" ); } catch( TransientObjectException e ) { // expected result log.trace( "handled expected exception", e ); s.getTransaction().rollback(); } finally { s.close(); } } finally { cleanupData(); }
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/jpa/cascade/CascadeTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/jpa/cascade/CascadeTest.java
Method name: void testOneToOneAssignedIds() Method name: void testManyToOnePropertyRefAssignedIds()
Number of AST nodes: 11 Number of AST nodes: 10
1
try {
1
try {
2
			Session s = openSession();
2
			Session s = openSession();
3
			s.beginTransaction();
3
			s.beginTransaction();
4
			ParentAssigned p = new ParentAssigned( new Long( 1 ), "parent" );
4
			ParentAssigned p = new ParentAssigned( new Long( 1 ), "parent" );
5
			ParentInfoAssigned info = new ParentInfoAssigned( "something secret" );
5
			OtherAssigned other = new 
6
			p.setInfo( info );
6
OtherAssigned( new Long( 2 ) );
7
			info.setOwner( p );
7
			other.setOwner( p );
8
			s.persist( p );
8
			s.persist( other );
9
			try {
9
			try {
10
				s.getTransaction().commit();
10
				s.getTransaction().commit();
11
				fail( "expecting TransientObjectException on flush" );
11
				fail( "expecting TransientObjectException on flush" );
12
			}
12
			}
13
			catch( TransientObjectException e ) {
13
			catch( TransientObjectException e ) {
14
				// expected result
14
				// expected result
15
				log.trace( "handled expected exception", e );
15
				log.trace( "handled expected exception", e );
16
				s.getTransaction().rollback();
16
				s.getTransaction().rollback();
17
			}
17
			}
18
			finally {
18
			finally {
19
				s.close();
19
				s.close();
20
			}
20
			}
21
		}
21
		}
22
		finally {
22
		finally {
23
			cleanupData();
23
			cleanupData();
24
		}
24
		}
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.4
Clones locationClones are declared in the same class
Number of node comparisons65
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements9
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)2.3
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    try
    1
    try
    2
    Session s = openSession();
    2
    Session s = openSession();
    3
    s.beginTransaction();
    3
    s.beginTransaction();
    4
    ParentAssigned p = new ParentAssigned(new Long(1), "parent");
    4
    ParentAssigned p = new ParentAssigned(new Long(1), "parent");
                                                                                                                
    5
    OtherAssigned other = new OtherAssigned(new Long(2));
    5
    ParentInfoAssigned info = new ParentInfoAssigned("something secret");
                                                                                                                                                
    6
    p.setInfo(info);
                                          
    7
    info.setOwner(p);
    7
    info.setOwner(p);
    6
    other.setOwner(p);
    Differences
    Expression1Expression2Difference
    infootherVARIABLE_NAME_MISMATCH
    org.hibernate.test.jpa.cascade.ParentInfoAssignedorg.hibernate.test.jpa.cascade.OtherAssignedVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.jpa.cascade.ParentInfoAssigned of variable info does not match with type org.hibernate.test.jpa.cascade.OtherAssigned of variable other
    • Make classes org.hibernate.test.jpa.cascade.ParentInfoAssigned and org.hibernate.test.jpa.cascade.OtherAssigned extend a common superclass
    6
    other.setOwner(p);
    8
    s.persist(p);
    8
    s.persist(p);
    7
    s.persist(other);
    Differences
    Expression1Expression2Difference
    potherVARIABLE_NAME_MISMATCH
    org.hibernate.test.jpa.cascade.ParentAssignedorg.hibernate.test.jpa.cascade.OtherAssignedVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Expression p cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Type org.hibernate.test.jpa.cascade.ParentAssigned of variable p does not match with type org.hibernate.test.jpa.cascade.OtherAssigned of variable other
    • Make classes org.hibernate.test.jpa.cascade.ParentAssigned and org.hibernate.test.jpa.cascade.OtherAssigned extend a common superclass
    7
    s.persist(other);
    9
    try
    8
    try
    10
    s.getTransaction().commit();
    9
    s.getTransaction().commit();
    11
    fail("expecting TransientObjectException on flush");
    10
    fail("expecting TransientObjectException on flush");
    Precondition Violations (4)
    Row Violation
    1Type org.hibernate.test.jpa.cascade.ParentInfoAssigned of variable info does not match with type org.hibernate.test.jpa.cascade.OtherAssigned of variable other
    2Expression p cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Type org.hibernate.test.jpa.cascade.ParentAssigned of variable p does not match with type org.hibernate.test.jpa.cascade.OtherAssigned of variable other
    4Clone fragment #1 returns variables p , while Clone fragment #2 returns variables