Session session = openSession(); Transaction txn = session.beginTransaction(); JobBatch batch = new JobBatch( new Date() ); batch.createJob().setProcessingInstructions( "Just do it!" ); batch.createJob().setProcessingInstructions( "I know you can do it!" ); // write the stuff to the database; at this stage all job.status values are zero session.persist( batch ); session.flush(); // behind the session's back, let's modify the statuses updateStatuses( session.connection() ); // Now lets refresh the persistent batch, and see if the refresh cascaded to the jobs collection elements session.refresh( batch ); Iterator itr = batch.getJobs().iterator(); while( itr.hasNext() ) { Job job = ( Job ) itr.next(); assertEquals( "Jobs not refreshed!", 1, job.getStatus() ); } txn.rollback(); session.close();
Session session = openSession(); session.delete("from A"); A savedA = new A(); session.save(savedA); B savedB = new B(); session.save(savedB); session.flush(); int count = session.createQuery("from A").list().size(); session.close(); session = openSession(); Query query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA", "a", A.class); List list = query.list(); assertNotNull(list); assertEquals(count, list.size()); session.connection().commit(); session.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/cascade/RefreshTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/SQLLoaderTest.java
Method name: void testRefreshCascade() Method name: void testFindBySQLDiscriminatedDiffSession()
Number of AST nodes: 15 Number of AST nodes: 16
1
Session session = openSession();
1
Session session = openSession();
2
		Transaction txn = session.beginTransaction();
2
		
3
		JobBatch batch = new JobBatch( new Date() );
4
		batch.createJob().setProcessingInstructions( "Just do it!" );
5
		batch.createJob().setProcessingInstructions( "I know you can do it!" );
6
		// write the stuff to the database; at this stage all job.status values are zero
7
		session.persist( batch 
3
session.delete("from A");
4
		A savedA = new A();
5
		session.save(savedA);
6
		B savedB = new B();
7
		session.save(savedB);
8
		session.flush();
8
);
9
		int count = session.createQuery("from A").list().size();
9
		session.flush();
10
		session.close();
10
		// behind the session's back, let's modify the statuses
11
		
11
		updateStatuses( session.connection() );
12
		// Now lets refresh the persistent batch, and see if the refresh cascaded to the jobs collection elements
13
		session.refresh( batch 
12
session = openSession();
14
);
13
		Query query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA", "a", A.class);
15
		Iterator itr = batch.getJobs().iterator();
14
		List list = query.list();
16
		while( itr.hasNext() ) {
15
		
17
			Job job = ( Job ) itr.next();
16
assertNotNull(list);
18
			assertEquals( "Jobs not refreshed!", 1, job.getStatus() );
17
		assertEquals(count, list.size());
19
		}
18
		
20
		txn.rollback();
19
session.connection().commit();
21
		session.close();
20
		session.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.0
Clones locationClones are in different classes having the same super class
Number of node comparisons192
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements5
    Number of unmapped statements in the first code fragment10
    Number of unmapped statements in the second code fragment11
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                                      
    1
    Session session = openSession();
    1
    Session session = openSession();
                                                                      
                                                            
    2
    session.delete("from A");
    2
    Transaction txn = session.beginTransaction();
                                                                                                
                                            
    3
    A savedA = new A();
    3
    JobBatch batch = new JobBatch(new Date());
                                                                                          
                                                    
    4
    session.save(savedA);
                                            
    5
    B savedB = new B();
                                                    
    6
    session.save(savedB);
                                                                                                                      
    8
    int count = session.createQuery("from A").list().size();
                                          
    9
    session.close();
                                                        
    10
    session = openSession();
    Preondition Violations
    Unmatched statement session=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10
    session = openSession();
                                                                                                                                                                                                                                                                                                                                                      
    11
    Query query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA", "a", A.class);
                                                          
    12
    List list = query.list();
    4
    batch.createJob().setProcessingInstructions("Just do it!");
    4
    batch.createJob().setProcessingInstructions("Just do it!");
    14
    assertEquals(count, list.size());
    Differences
    Expression1Expression2Difference
    setProcessingInstructionsassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    batch.createJob().setProcessingInstructions("Just do it!")assertEquals(count,list.size())ARGUMENT_NUMBER_MISMATCH
    batch.createJob()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression batch.createJob().setProcessingInstructions("Just do it!") is a void method call, and thus it cannot be parameterized
    Expression assertEquals(count,list.size()) is a void method call, and thus it cannot be parameterized
    Expression batch.createJob().setProcessingInstructions("Just do it!") is a void method call, and thus it cannot be parameterized
    Expression assertEquals(count,list.size()) is a void method call, and thus it cannot be parameterized
    14
    assertEquals(count, list.size());
    5
    batch.createJob().setProcessingInstructions("I know you can do it!");
                                                                                                                                                    
    6
    session.persist(batch);
                                                        
    7
    session.flush();
    7
    session.flush();
    7
    session.flush();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable session does not match with type org.hibernate.classic.Session of variable session
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    7
    session.flush();
    8
    updateStatuses(session.connection());
    8
    updateStatuses(session.connection());
    15
    session.connection().commit();
    Differences
    Expression1Expression2Difference
    updateStatusescommitMETHOD_INVOCATION_NAME_MISMATCH
    updateStatuses(session.connection())session.connection().commit()ARGUMENT_NUMBER_MISMATCH
    session.connection()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression updateStatuses(session.connection()) is a void method call, and thus it cannot be parameterized
    Expression session.connection().commit() is a void method call, and thus it cannot be parameterized
    Expression updateStatuses(session.connection()) is a void method call, and thus it cannot be parameterized
    Expression session.connection().commit() is a void method call, and thus it cannot be parameterized
    15
    session.connection().commit();
    9
    session.refresh(batch);
                                                        
    10
    Iterator itr = batch.getJobs().iterator();
                                                                                            
    11
    while (itr.hasNext())
                                                    
    12
    Job job = (Job)itr.next();
                                                            
    13
    assertEquals("Jobs not refreshed!", 1, job.getStatus());
                                                                                                                        
    14
    txn.rollback();
    14
    txn.rollback();
    13
    assertNotNull(list);
    Differences
    Expression1Expression2Difference
    rollbackassertNotNullMETHOD_INVOCATION_NAME_MISMATCH
    txn.rollback()assertNotNull(list)ARGUMENT_NUMBER_MISMATCH
    txnMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression txn.rollback() is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized
    Expression txn.rollback() is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized
    13
    assertNotNull(list);
    15
    session.close();
    15
    session.close();
    16
    session.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable session does not match with type org.hibernate.classic.Session of variable session
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    16
    session.close();
    Precondition Violations (15)
    Row Violation
    1Unmatched statement session=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Expression batch.createJob().setProcessingInstructions("Just do it!") is a void method call, and thus it cannot be parameterized
    3Expression assertEquals(count,list.size()) is a void method call, and thus it cannot be parameterized
    4Expression batch.createJob().setProcessingInstructions("Just do it!") is a void method call, and thus it cannot be parameterized
    5Expression assertEquals(count,list.size()) is a void method call, and thus it cannot be parameterized
    6Type org.hibernate.Session of variable session does not match with type org.hibernate.classic.Session of variable session
    7Expression updateStatuses(session.connection()) is a void method call, and thus it cannot be parameterized
    8Expression session.connection().commit() is a void method call, and thus it cannot be parameterized
    9Expression updateStatuses(session.connection()) is a void method call, and thus it cannot be parameterized
    10Expression session.connection().commit() is a void method call, and thus it cannot be parameterized
    11Expression txn.rollback() is a void method call, and thus it cannot be parameterized
    12Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized
    13Expression txn.rollback() is a void method call, and thus it cannot be parameterized
    14Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized
    15Type org.hibernate.Session of variable session does not match with type org.hibernate.classic.Session of variable session