Session s = openSession(); Transaction tx = s.beginTransaction(); Node dupe = new Node("dupe"); s.persist(dupe); s.persist(dupe); tx.commit(); s.close(); s = openSession(); tx = s.beginTransaction(); s.persist(dupe); try { tx.commit(); assertFalse(true); } catch (ConstraintViolationException cve) { //verify that an exception is thrown! } tx.rollback(); s.close(); Node nondupe = new Node("nondupe"); nondupe.addChild(dupe); s = openSession(); tx = s.beginTransaction(); s.persist(nondupe); try { tx.commit(); assertFalse(true); } catch (ConstraintViolationException cve) { //verify that an exception is thrown! } tx.rollback(); s.close();
Session s = openSession(); Transaction tx = s.beginTransaction(); NumberedNode dupe = new NumberedNode("dupe"); s.persist(dupe); s.persist(dupe); tx.commit(); s.close(); s = openSession(); tx = s.beginTransaction(); try { s.persist(dupe); assertFalse(true); } catch (PersistentObjectException poe) { //verify that an exception is thrown! } tx.rollback(); s.close(); NumberedNode nondupe = new NumberedNode("nondupe"); nondupe.addChild(dupe); s = openSession(); tx = s.beginTransaction(); try { s.persist(nondupe); assertFalse(true); } catch (PersistentObjectException poe) { //verify that an exception is thrown! } tx.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/ops/CreateTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/ops/CreateTest.java
Method name: void testCreateException() Method name: void testCreateExceptionWithGeneratedId()
Number of AST nodes: 25 Number of AST nodes: 23
1
Session s = openSession();
1
Session s = openSession();
2
		Transaction tx = s.beginTransaction();
2
		Transaction tx = s.beginTransaction();
3
		Node dupe = new Node("dupe");
3
		NumberedNode dupe = new NumberedNode("dupe");
4
		s.persist(dupe);
4
		s.persist(dupe);
5
		s.persist(dupe);
5
		s.persist(dupe);
6
		tx.commit();
6
		tx.commit();
7
		s.close();
7
		s.close();
8
		s = openSession();
8
		s = openSession();
9
		tx = s.beginTransaction();
9
		tx = s.beginTransaction();
10
		
10
		try {
11
s.persist(dupe);
11
			s.persist(dupe);
12
		try {
12
		
13
			tx.commit();
14
			assertFalse(true);
13
	assertFalse(true);
15
		}
14
		}
16
		catch (ConstraintViolationException cve) {
15
		catch (PersistentObjectException poe) {
17
			//verify that an exception is thrown!
16
			//verify that an exception is thrown!
18
		}
17
		}
19
		tx.rollback();
18
		tx.rollback();
20
		s.close();
19
		s.close();
21
		Node nondupe = new Node("nondupe");
20
		NumberedNode nondupe = new NumberedNode("nondupe");
22
		nondupe.addChild(dupe);
21
		nondupe.addChild(dupe);
23
		s = openSession();
22
		s = openSession();
24
		tx = s.beginTransaction();
23
		tx = s.beginTransaction();
25
		
24
		try {
26
s.persist(nondupe);
25
			s.persist(nondupe);
27
		try {
26
		
28
			tx.commit();
29
			assertFalse(true);
27
	assertFalse(true);
30
		}
28
		}
31
		catch (ConstraintViolationException cve) {
29
		catch (PersistentObjectException poe) {
32
			//verify that an exception is thrown!
30
			//verify that an exception is thrown!
33
		}
31
		}
34
		tx.rollback();
32
		tx.rollback();
35
		s.close();
33
		s.close();
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 comparisons103
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements18
    Number of unmapped statements in the first code fragment7
    Number of unmapped statements in the second code fragment5
    Time elapsed for statement mapping (ms)9.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
    2
    Transaction tx = s.beginTransaction();
    2
    Transaction tx = s.beginTransaction();
                                                                                                
    3
    NumberedNode dupe = new NumberedNode("dupe");
    3
    Node dupe = new Node("dupe");
                                                                
    4
    s.persist(dupe);
    4
    s.persist(dupe);
    4
    s.persist(dupe);
    Differences
    Expression1Expression2Difference
    org.hibernate.test.ops.Nodeorg.hibernate.test.ops.NumberedNodeVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.ops.Node of variable dupe does not match with type org.hibernate.test.ops.NumberedNode of variable dupe
    • Make classes org.hibernate.test.ops.Node and org.hibernate.test.ops.NumberedNode extend a common superclass
    4
    s.persist(dupe);
    5
    s.persist(dupe);
    5
    s.persist(dupe);
    5
    s.persist(dupe);
    Differences
    Expression1Expression2Difference
    org.hibernate.test.ops.Nodeorg.hibernate.test.ops.NumberedNodeVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.ops.Node of variable dupe does not match with type org.hibernate.test.ops.NumberedNode of variable dupe
    • Make classes org.hibernate.test.ops.Node and org.hibernate.test.ops.NumberedNode extend a common superclass
    5
    s.persist(dupe);
    6
    tx.commit();
    6
    tx.commit();
    7
    s.close();
    7
    s.close();
    8
    s = openSession();
    8
    s = openSession();
    9
    tx = s.beginTransaction();
    9
    tx = s.beginTransaction();
    10
    s.persist(dupe);
    10
    s.persist(dupe);
    Preondition Violations
    Unmatched statement s.persist(dupe); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                            
    11
    try
    11
    try
    10
    try
    Differences
    Expression1Expression2Difference
    org.hibernate.exception.ConstraintViolationExceptionorg.hibernate.PersistentObjectExceptionSUBCLASS_TYPE_MISMATCH
    cvepoeVARIABLE_NAME_MISMATCH
    org.hibernate.exception.ConstraintViolationExceptionorg.hibernate.PersistentObjectExceptionSUBCLASS_TYPE_MISMATCH
    10
    try
                                            
    11
    s.persist(dupe);
    Preondition Violations
    Unmatched statement s.persist(dupe); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement s.persist(dupe); 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
    11
    s.persist(dupe);
    12
    tx.commit();
    12
    tx.commit();
    12
    assertFalse(true);
    Differences
    Expression1Expression2Difference
    commitassertFalseMETHOD_INVOCATION_NAME_MISMATCH
    tx.commit()assertFalse(true)ARGUMENT_NUMBER_MISMATCH
    txMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression tx.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression tx.commit() is a void method call, and thus it cannot be parameterized
    Expression assertFalse(true) is a void method call, and thus it cannot be parameterized
    Expression tx.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression tx.commit() is a void method call, and thus it cannot be parameterized
    Expression assertFalse(true) is a void method call, and thus it cannot be parameterized
    12
    assertFalse(true);
    13
    assertFalse(true);
                                                
    14
    tx.rollback();
    13
    tx.rollback();
    15
    s.close();
    14
    s.close();
                                                                                                              
    15
    NumberedNode nondupe = new NumberedNode("nondupe");
                                                          
    16
    nondupe.addChild(dupe);
    16
    Node nondupe = new Node("nondupe");
                                                                              
    17
    nondupe.addChild(dupe);
                                                          
    18
    s = openSession();
    17
    s = openSession();
    19
    tx = s.beginTransaction();
    18
    tx = s.beginTransaction();
    20
    s.persist(nondupe);
                                                  
    21
    try
    21
    try
    19
    try
    Differences
    Expression1Expression2Difference
    org.hibernate.exception.ConstraintViolationExceptionorg.hibernate.PersistentObjectExceptionSUBCLASS_TYPE_MISMATCH
    cvepoeVARIABLE_NAME_MISMATCH
    org.hibernate.exception.ConstraintViolationExceptionorg.hibernate.PersistentObjectExceptionSUBCLASS_TYPE_MISMATCH
    19
    try
                                                  
    20
    s.persist(nondupe);
    Preondition Violations
    Unmatched statement s.persist(nondupe); 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
    20
    s.persist(nondupe);
    22
    tx.commit();
    22
    tx.commit();
    21
    assertFalse(true);
    Differences
    Expression1Expression2Difference
    commitassertFalseMETHOD_INVOCATION_NAME_MISMATCH
    tx.commit()assertFalse(true)ARGUMENT_NUMBER_MISMATCH
    txMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression tx.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression tx.commit() is a void method call, and thus it cannot be parameterized
    Expression assertFalse(true) is a void method call, and thus it cannot be parameterized
    Expression tx.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression tx.commit() is a void method call, and thus it cannot be parameterized
    Expression assertFalse(true) is a void method call, and thus it cannot be parameterized
    21
    assertFalse(true);
    23
    assertFalse(true);
                                                
    24
    tx.rollback();
    22
    tx.rollback();
    25
    s.close();
    23
    s.close();
    Precondition Violations (18)
    Row Violation
    1Type org.hibernate.test.ops.Node of variable dupe does not match with type org.hibernate.test.ops.NumberedNode of variable dupe
    2Type org.hibernate.test.ops.Node of variable dupe does not match with type org.hibernate.test.ops.NumberedNode of variable dupe
    3Unmatched statement s.persist(dupe); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement s.persist(dupe); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement s.persist(dupe); 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
    6Expression tx.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression tx.commit() is a void method call, and thus it cannot be parameterized
    8Expression assertFalse(true) is a void method call, and thus it cannot be parameterized
    9Expression tx.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression tx.commit() is a void method call, and thus it cannot be parameterized
    11Expression assertFalse(true) is a void method call, and thus it cannot be parameterized
    12Unmatched statement s.persist(nondupe); 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
    13Expression tx.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression tx.commit() is a void method call, and thus it cannot be parameterized
    15Expression assertFalse(true) is a void method call, and thus it cannot be parameterized
    16Expression tx.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression tx.commit() is a void method call, and thus it cannot be parameterized
    18Expression assertFalse(true) is a void method call, and thus it cannot be parameterized