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" ); Child c = new Child( "child" ); c.setParent( p ); s.persist( 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(); }
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 testManyToOneGeneratedIds()
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
			Child c = new Child( "child" );
6
			c.setParent( p );
6
			c.setParent( p );
7
			s.save( c );
7
			s.persist( c );
8
			try {
8
			try {
9
				s.getTransaction().commit();
9
				s.getTransaction().commit();
10
				fail( "expecting TransientObjectException on flush" );
10
				fail( "expecting TransientObjectException on flush" );
11
			}
11
			}
12
			catch( TransientObjectException e ) {
12
			catch( TransientObjectException e ) {
13
				// expected result
13
				// expected result
14
				log.trace( "handled expected exception", e );
14
				log.trace( "handled expected exception", e );
15
				s.getTransaction().rollback();
15
				s.getTransaction().rollback();
16
			}
16
			}
17
			finally {
17
			finally {
18
				s.close();
18
				s.close();
19
			}
19
			}
20
		}
20
		}
21
		finally {
21
		finally {
22
			cleanupData();
22
			cleanupData();
23
		}
23
		}
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 statements9
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)3.0
    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
    Child c = new Child("child");
    5
    Child c = new Child("child");
    6
    c.setParent(p);
    6
    c.setParent(p);
                                    
    7
    s.persist(c);
    Preondition Violations
    Unmatched statement s.persist(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement s.persist(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
    7
    s.persist(c);
    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 (4)
    Row Violation
    1Unmatched statement s.persist(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement s.persist(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
    3Unmatched statement s.save(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched 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