try { // The new membership is transient (it has a null surrogate ID), so // Hibernate assumes that it should be added to the collection. // Inserts are done before deletes, so a ConstraintViolationException // will be thrown on the insert because the unique constraint on the // user and group IDs in the join table is violated. See HHH-2801. s.merge( getUser() ); s.getTransaction().commit(); fail( "should have failed because inserts are before deletes"); } catch( ConstraintViolationException ex ) { // expected s.getTransaction().rollback(); } finally { s.close(); }
try { s.merge( entity ); s.getTransaction().commit(); fail( "was expecting staleness error" ); } catch ( StaleObjectStateException expected ) { // expected outcome... } 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/manytomanyassociationclass/surrogateid/generated/ManyToManyAssociationClassGeneratedIdTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/ops/MergeTest.java
Method name: void testRemoveAndAddEqualCollection() Method name: void testMergeStaleVersionFails()
Number of AST nodes: 4 Number of AST nodes: 4
1
try {
1
try {
2
			// The new membership is transient (it has a null surrogate ID), so
2
			
3
			// Hibernate assumes that it should be added to the collection.
4
			// Inserts are done before deletes, so a ConstraintViolationException
5
			// will be thrown on the insert because the unique constraint on the
6
			// user and group IDs in the join table is violated. See HHH-2801.
7
			s.merge( getUser() );
3
s.merge( entity );
8
			s.getTransaction().commit();
4
			s.getTransaction().commit();
9
			fail( "should have failed because inserts are before deletes");
5
			fail( "was expecting staleness error" );
10
		}
6
		}
11
		catch( ConstraintViolationException ex ) {
7
		catch ( StaleObjectStateException expected ) {
12
			// expected
8
			// expected outcome...
9
		}
10
		finally {
13
			s.getTransaction().rollback();
11
			s.getTransaction().rollback();
14
		}
15
		finally {
16
			s.close();
12
			s.close();
17
		}
13
		}
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.2
Clones locationClones are in different classes having the same super class
Number of node comparisons1