try { Session s = openSession(); s.beginTransaction(); Parent p = new Parent( "parent" ); Child c = new Child( "child" ); c.setParent( p ); s.save( c ); 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(); Parent p = new Parent( "parent" ); Other other = new Other(); 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 testManyToOneGeneratedIdsOnSave() Method name: void testManyToOnePropertyRefGeneratedIds()
Number of AST nodes: 10 Number of AST nodes: 10
1
try {
1
try {
2
			Session s = openSession();
2
			Session s = openSession();
3
			s.beginTransaction();
3
			s.beginTransaction();
4
			Parent p = new Parent( "parent" );
4
			Parent p = new Parent( "parent" );
5
			Child c = new Child( "child" );
5
			
6
			c.setParent( p );
7
			s.save( c
6
Other other = new Other();
7
			other.setOwner( p );
8
 );
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 cases1
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.4
Clones locationClones are declared in the same class
Number of node comparisons58
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements7
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)2.5
    Clone typeType 2
    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
    Parent p = new Parent("parent");
    4
    Parent p = new Parent("parent");
                                                          
    5
    Other other = new Other();
    5
    Child c = new Child("child");
    5
    Child c = new Child("child");
    Preondition Violations
    Unmatched statement Child c=new Child("child"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                
                                              
    6
    other.setOwner(p);
    Preondition Violations
    Unmatched statement other.setOwner(p); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6
    other.setOwner(p);
    6
    c.setParent(p);
    6
    c.setParent(p);
    Preondition Violations
    Unmatched statement c.setParent(p); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                        
                                            
    7
    s.persist(other);
    Preondition Violations
    Unmatched statement s.persist(other); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement s.persist(other); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    7
    s.persist(other);
    7
    s.save(c);
    7
    s.save(c);
    Preondition Violations
    Unmatched statement s.save(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement s.save(c); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
                              
    8
    try
    8
    try
    9
    s.getTransaction().commit();
    9
    s.getTransaction().commit();
    10
    fail("expecting TransientObjectException on flush");
    10
    fail("expecting TransientObjectException on flush");
    Precondition Violations (7)
    Row Violation
    1Unmatched statement Child c=new Child("child"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement other.setOwner(p); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement c.setParent(p); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement s.persist(other); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement s.persist(other); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    6Unmatched statement s.save(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched statement s.save(c); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted