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 statements3
    Number of unmapped statements in the first code fragment9
    Number of unmapped statements in the second code fragment13
    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();
    1
    Session session = openSession();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    1
    Session session = openSession();
                                                            
    2
    session.delete("from A");
    Preondition Violations
    Unmatched statement session.delete("from A"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2
    session.delete("from A");
    2
    Transaction txn = session.beginTransaction();
    2
    Transaction txn = session.beginTransaction();
    Preondition Violations
    Unmatched statement Transaction txn=session.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                
                                            
    3
    A savedA = new A();
    3
    JobBatch batch = new JobBatch(new Date());
    3
    JobBatch batch = new JobBatch(new Date());
    Preondition Violations
    Unmatched statement JobBatch batch=new JobBatch(new Date()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                          
                                                    
    4
    session.save(savedA);
    Preondition Violations
    Unmatched statement session.save(savedA); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4
    session.save(savedA);
    4
    batch.createJob().setProcessingInstructions("Just do it!");
                                                                                                                                
                                            
    5
    B savedB = new B();
    5
    batch.createJob().setProcessingInstructions("I know you can do it!");
                                                                                                                                                    
                                                    
    6
    session.save(savedB);
    Preondition Violations
    Unmatched statement session.save(savedB); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6
    session.save(savedB);
    6
    session.persist(batch);
    6
    session.persist(batch);
    7
    session.flush();
    Differences
    Expression1Expression2Difference
    persistflushMETHOD_INVOCATION_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    session.persist(batch)session.flush()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression session.persist(batch) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.persist(batch) is a void method call, and thus it cannot be parameterized
    Expression session.flush() is a void method call, and thus it cannot be parameterized
    Expression session.persist(batch) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.persist(batch) is a void method call, and thus it cannot be parameterized
    Expression session.flush() is a void method call, and thus it cannot be parameterized
    7
    session.flush();
    7
    session.flush();
    7
    session.flush();
    Preondition Violations
    Unmatched statement session.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                          
                                                                                                                      
    8
    int count = session.createQuery("from A").list().size();
    Preondition Violations
    Unmatched statement int count=session.createQuery("from A").list().size(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8
    int count = session.createQuery("from A").list().size();
    8
    updateStatuses(session.connection());
    8
    updateStatuses(session.connection());
    Preondition Violations
    Unmatched statement updateStatuses(session.connection()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                    
    9
    session.refresh(batch);
    9
    session.refresh(batch);
    Preondition Violations
    Unmatched statement session.refresh(batch); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                        
                                                        
    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();
    10
    Iterator itr = batch.getJobs().iterator();
                                                                                            
    14
    txn.rollback();
    14
    txn.rollback();
    Preondition Violations
    Unmatched statement txn.rollback(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                          
    15
    session.close();
    15
    session.close();
    9
    session.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    9
    session.close();
                                                                                                                                                                                                                                                                                                                                                      
    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);
    Preondition Violations
    Unmatched statement 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); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    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();
    Preondition Violations
    Unmatched statement List list=query.list(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    12
    List list = query.list();
                                                    
    13
    assertNotNull(list);
                                                                            
    14
    assertEquals(count, list.size());
                                                                        
    15
    session.connection().commit();
                                            
    16
    session.close();
    Precondition Violations (22)
    Row Violation
    1Unmatched statement session.delete("from A"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement Transaction txn=session.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement JobBatch batch=new JobBatch(new Date()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Unmatched statement session.save(savedA); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement session.save(savedB); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Expression session.persist(batch) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression session.persist(batch) is a void method call, and thus it cannot be parameterized
    9Expression session.flush() is a void method call, and thus it cannot be parameterized
    10Expression session.persist(batch) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression session.persist(batch) is a void method call, and thus it cannot be parameterized
    13Expression session.flush() is a void method call, and thus it cannot be parameterized
    14Unmatched statement session.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15Unmatched statement int count=session.createQuery("from A").list().size(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16Unmatched statement updateStatuses(session.connection()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17Unmatched statement session.refresh(batch); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    18Unmatched statement session=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19Unmatched statement txn.rollback(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    20Unmatched statement 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); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    21Unmatched statement List list=query.list(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    22Clone fragment #1 returns variable session with type org.hibernate.Session , while Clone fragment #2 returns variable session with type org.hibernate.classic.Session