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 { // 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(); }
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/manytomanyassociationclass/surrogateid/generated/ManyToManyAssociationClassGeneratedIdTest.java
Method name: void testRemoveAndAddEqualElement() Method name: void testRemoveAndAddEqualElementNonKeyModified()
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
			// The new membership is transient (it has a null surrogate ID), so
3
			// Hibernate assumes that it should be added to the collection.
3
			// Hibernate assumes that it should be added to the collection.
4
			// Inserts are done before deletes, so a ConstraintViolationException
4
			// Inserts are done before deletes, so a ConstraintViolationException
5
			// will be thrown on the insert because the unique constraint on the
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.
6
			// user and group IDs in the join table is violated. See HHH-2801.
7
			s.merge( getUser() );
7
			s.merge( getUser() );
8
			s.getTransaction().commit();
8
			s.getTransaction().commit();
9
			fail( "should have failed because inserts are before deletes");
9
			fail( "should have failed because inserts are before deletes");
10
		}
10
		}
11
		catch( ConstraintViolationException ex ) {
11
		catch( ConstraintViolationException ex ) {
12
			// expected
12
			// expected
13
			s.getTransaction().rollback();
13
			s.getTransaction().rollback();
14
		}
14
		}
15
		finally {
15
		finally {
16
			s.close();
16
			s.close();
17
		}
17
		}
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.2
Clones locationClones are declared in the same class
Number of node comparisons16
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements4
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)12.9
    Clone typeType 1
    Mapped Statements
    ID Statement ID Statement
    5
    try
    7
    try
    6
    s.merge(getUser());
    8
    s.merge(getUser());
    7
    s.getTransaction().commit();
    9
    s.getTransaction().commit();
    8
    fail("should have failed because inserts are before deletes");
    10
    fail("should have failed because inserts are before deletes");
    Precondition Violations (0)
    Row Violation