Session s = openSession(); Transaction tx = s.beginTransaction(); VersionedEntity entity = new VersionedEntity( "test", "test" ); s.persist( entity ); s.merge( new VersionedEntity( "test", "test-2" ) ); try { // control operation... s.saveOrUpdate( new VersionedEntity( "test", "test-3" ) ); fail( "saveOrUpdate() should fail here" ); } catch( NonUniqueObjectException expected ) { // expected behavior } tx.commit(); s.close(); cleanup();
Session s = openSession(); Transaction tx = s.beginTransaction(); TimestampedEntity entity = new TimestampedEntity( "test", "test" ); s.persist( entity ); s.merge( new TimestampedEntity( "test", "test-2" ) ); try { // control operation... s.saveOrUpdate( new TimestampedEntity( "test", "test-3" ) ); fail( "saveOrUpdate() should fail here" ); } catch( NonUniqueObjectException expected ) { // expected behavior } tx.commit(); s.close(); cleanup();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/ops/MergeTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/ops/MergeTest.java
Method name: void testPersistThenMergeInSameTxnWithVersion() Method name: void testPersistThenMergeInSameTxnWithTimestamp()
Number of AST nodes: 11 Number of AST nodes: 11
1
Session s = openSession();
1
Session s = openSession();
2
		Transaction tx = s.beginTransaction();
2
		Transaction tx = s.beginTransaction();
3
		VersionedEntity entity = new VersionedEntity( "test", "test" );
3
		TimestampedEntity entity = new TimestampedEntity( "test", "test" );
4
		s.persist( entity );
4
		s.persist( entity );
5
		s.merge( new VersionedEntity( "test", "test-2" ) );
5
		s.merge( new TimestampedEntity( "test", "test-2" ) );
6
		try {
6
		try {
7
			// control operation...
7
			// control operation...
8
			s.saveOrUpdate( new VersionedEntity( "test", "test-3" ) );
8
			s.saveOrUpdate( new TimestampedEntity( "test", "test-3" ) );
9
			fail( "saveOrUpdate() should fail here" );
9
			fail( "saveOrUpdate() should fail here" );
10
		}
10
		}
11
		catch( NonUniqueObjectException expected ) {
11
		catch( NonUniqueObjectException expected ) {
12
			// expected behavior
12
			// expected behavior
13
		}
13
		}
14
		tx.commit();
14
		tx.commit();
15
		s.close();
15
		s.close();
16
		cleanup();
16
		cleanup();
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.1
Clones locationClones are declared in the same class
Number of node comparisons51
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements10
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)2.2
    Clone typeType 2
    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
    TimestampedEntity entity = new TimestampedEntity("test", "test");
    3
    VersionedEntity entity = new VersionedEntity("test", "test");
                                                                                                                              
    4
    s.persist(entity);
    4
    s.persist(entity);
    4
    s.persist(entity);
    Differences
    Expression1Expression2Difference
    org.hibernate.test.ops.VersionedEntityorg.hibernate.test.ops.TimestampedEntityVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.ops.VersionedEntity of variable entity does not match with type org.hibernate.test.ops.TimestampedEntity of variable entity
    • Make classes org.hibernate.test.ops.VersionedEntity and org.hibernate.test.ops.TimestampedEntity extend a common superclass
    4
    s.persist(entity);
    5
    s.merge(new VersionedEntity("test", "test-2"));
    5
    s.merge(new VersionedEntity("test", "test-2"));
    5
    s.merge(new TimestampedEntity("test", "test-2"));
    Differences
    Expression1Expression2Difference
    org.hibernate.test.ops.VersionedEntityorg.hibernate.test.ops.TimestampedEntityVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.ops.VersionedEntity of variable new VersionedEntity("test","test-2") does not match with type org.hibernate.test.ops.TimestampedEntity of variable new TimestampedEntity("test","test-2")
    • Make classes org.hibernate.test.ops.VersionedEntity and org.hibernate.test.ops.TimestampedEntity extend a common superclass
    5
    s.merge(new TimestampedEntity("test", "test-2"));
    6
    try
    6
    try
    7
    s.saveOrUpdate(new VersionedEntity("test", "test-3"));
    7
    s.saveOrUpdate(new VersionedEntity("test", "test-3"));
    7
    s.saveOrUpdate(new TimestampedEntity("test", "test-3"));
    Differences
    Expression1Expression2Difference
    org.hibernate.test.ops.VersionedEntityorg.hibernate.test.ops.TimestampedEntityVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.ops.VersionedEntity of variable new VersionedEntity("test","test-3") does not match with type org.hibernate.test.ops.TimestampedEntity of variable new TimestampedEntity("test","test-3")
    • Make classes org.hibernate.test.ops.VersionedEntity and org.hibernate.test.ops.TimestampedEntity extend a common superclass
    7
    s.saveOrUpdate(new TimestampedEntity("test", "test-3"));
    8
    fail("saveOrUpdate() should fail here");
    8
    fail("saveOrUpdate() should fail here");
    9
    tx.commit();
    9
    tx.commit();
    10
    s.close();
    10
    s.close();
    11
    cleanup();
    11
    cleanup();
    Precondition Violations (3)
    Row Violation
    1Type org.hibernate.test.ops.VersionedEntity of variable entity does not match with type org.hibernate.test.ops.TimestampedEntity of variable entity
    2Type org.hibernate.test.ops.VersionedEntity of variable new VersionedEntity("test","test-2") does not match with type org.hibernate.test.ops.TimestampedEntity of variable new TimestampedEntity("test","test-2")
    3Type org.hibernate.test.ops.VersionedEntity of variable new VersionedEntity("test","test-3") does not match with type org.hibernate.test.ops.TimestampedEntity of variable new TimestampedEntity("test","test-3")