Session s = openSession(); Transaction t = s.beginTransaction(); Address address = new Address(); address.setInfo( "123 Main St." ); Suite suite = new Suite(); address.getSuites().add( suite ); s.save( address ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); Note note = new Note(); note.setDescription( "a description" ); suite.getNotes().add( note ); address.getSuites().clear(); s.saveOrUpdate( address ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); Long count = ( Long ) s.createQuery( "select count(*) from Suite" ).list().get( 0 ); assertEquals( "all-delete-orphan not cascaded properly to cleared persistent collection entities", 0, count.longValue() ); count = ( Long ) s.createQuery( "select count(*) from Note" ).list().get( 0 ); assertEquals( 0, count.longValue() ); s.delete( address ); t.commit(); s.close();
SessionFactory sf = getSessions(); Statistics stats = sf.getStatistics(); boolean isStats = stats.isStatisticsEnabled(); stats.clear(); stats.setStatisticsEnabled(true); Session s = sf.openSession(); assertEquals( 1, stats.getSessionOpenCount() ); s.close(); assertEquals( 1, stats.getSessionCloseCount() ); s = sf.openSession(); Transaction tx = s.beginTransaction(); A a = new A(); a.setName("mya"); s.save(a); a.setName("b"); tx.commit(); s.close(); assertEquals( 1, stats.getFlushCount() ); s = sf.openSession(); tx = s.beginTransaction(); String hql = "from " + A.class.getName(); Query q = s.createQuery(hql); q.list(); tx.commit(); s.close(); assertEquals(1, stats.getQueryExecutionCount() ); assertEquals(1, stats.getQueryStatistics(hql).getExecutionCount() ); stats.setStatisticsEnabled(isStats);
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/StatisticsTest.java
Method name: void testCascadeAllDeleteOrphanFromClearedPersistentAssnToTransientEntity() Method name: void testSessionStats()
Number of AST nodes: 27 Number of AST nodes: 28
1
Session s = openSession();
1
SessionFactory sf = getSessions();
2
		Transaction t = s.beginTransaction();
2
		Statistics stats = sf.getStatistics();
3
		Address address = new Address
3
		boolean isStats = stats.isStatisticsEnabled();
4
();
4
		stats.clear();
5
		address.setInfo( "123 Main St." );
5
		stats.setStatisticsEnabled(true);
6
		Suite suite = new Suite();
6
		Session s = sf.openSession();
7
		address.getSuites().add( suite );
7
		a
8
		s.save( address );
8
ssertEquals( 1, stats.getSessionOpenCount() );
9
		t.commit();
9
		s.close();
10
		s.close();
10
		
11

11
assertEquals( 1, stats.getSessionCloseCount() );
12
		s = openSession();
12
		s = sf.openSession();
13
		t = s.beginTransaction();
13
		Transaction tx = s.beginTransaction();
14
		Note note = new Note();
14
		A a = new A();
15
		note.setDescription( "a description" );
15
		a.setName("mya");
16
		suite.getNotes().add( note );
16
		s
17
		address.getSuites().clear();
17
.save(a);
18
		s.saveOrUpdate( address );
18
		a.setName("b");
19
		t.commit();
19
		tx.commit();
20
		s.close();
20
		s.close();
21

21
		assertEquals( 1, stats.getFlushCount() );
22
		s = openSession();
22
		s = sf.openSession();
23
		t = s.beginTransaction();
23
		tx = s.beginTransaction();
24
		Long count = ( Long )
24
		String hql = "from " + A.class.getName();
25
 s.createQuery( "select count(*) from Suite" ).list().get( 0 
25
		Query q = s.createQuery(hql);
26
		q.list();
27
		tx.commit();
26
);
28
		s.close();
27
		assertEquals( "all-delete-orphan not cascaded properly to cleared persistent collection entities", 0, count.longValue() );
29
		assertEquals(1, stats.getQueryExecutionCount() );
28
		count = ( Long ) s.createQuery( "select count(*) from Note" ).list().get( 0 );
30
		
29
		assertEquals( 0, count.longValue() );
31
assertEquals(1, stats.getQueryStatistics(hql).getExecutionCount() );
32
		
30
		s.delete( address );
33
		s
31
		t.commit();
32
		s.close();
34
tats.setStatisticsEnabled(isStats);
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 comparisons522
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements11
    Number of unmapped statements in the first code fragment16
    Number of unmapped statements in the second code fragment17
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                                          
    1
    SessionFactory sf = getSessions();
                                                                                  
    2
    Statistics stats = sf.getStatistics();
    Preondition Violations
    Unmatched statement Statistics stats=sf.getStatistics(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2
    Statistics stats = sf.getStatistics();
                                                                                                  
    3
    boolean isStats = stats.isStatisticsEnabled();
                                      
    4
    stats.clear();
    Preondition Violations
    Unmatched statement stats.clear(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4
    stats.clear();
    1
    Session s = openSession();
    1
    Session s = openSession();
    6
    Session s = sf.openSession();
    Differences
    Expression1Expression2Difference
    sfMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6
    Session s = sf.openSession();
    2
    Transaction t = s.beginTransaction();
    2
    Transaction t = s.beginTransaction();
    11
    Transaction tx = s.beginTransaction();
    Differences
    Expression1Expression2Difference
    ttxVARIABLE_NAME_MISMATCH
    11
    Transaction tx = s.beginTransaction();
    3
    Address address = new Address();
                                                                      
    4
    address.setInfo("123 Main St.");
    4
    address.setInfo("123 Main St.");
    Preondition Violations
    Unmatched statement address.setInfo("123 Main St."); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                          
                                                                            
    5
    stats.setStatisticsEnabled(true);
    Preondition Violations
    Unmatched statement stats.setStatisticsEnabled(true); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    5
    stats.setStatisticsEnabled(true);
    5
    Suite suite = new Suite();
                                                          
    6
    address.getSuites().add(suite);
                                                                        
                                                                                                  
    7
    assertEquals(1, stats.getSessionOpenCount());
    7
    s.save(address);
    7
    s.save(address);
    Preondition Violations
    Unmatched statement s.save(address); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                          
                                                                                                    
    9
    assertEquals(1, stats.getSessionCloseCount());
    8
    t.commit();
    8
    t.commit();
    16
    tx.commit();
    Differences
    Expression1Expression2Difference
    ttxVARIABLE_NAME_MISMATCH
    16
    tx.commit();
    9
    s.close();
    8
    s.close();
    10
    s = openSession();
    10
    s = openSession();
    10
    s = sf.openSession();
    Differences
    Expression1Expression2Difference
    sfMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10
    s = sf.openSession();
    11
    t = s.beginTransaction();
    11
    t = s.beginTransaction();
    Preondition Violations
    Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                          
                                    
    12
    A a = new A();
    12
    Note note = new Note();
                                                      
                                              
    13
    a.setName("mya");
    Preondition Violations
    Unmatched statement a.setName("mya"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    13
    a.setName("mya");
    13
    note.setDescription("a description");
    13
    note.setDescription("a description");
    Preondition Violations
    Unmatched statement note.setDescription("a description"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                      
                                
    14
    s.save(a);
    Preondition Violations
    Unmatched statement s.save(a); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14
    s.save(a);
    14
    suite.getNotes().add(note);
                                                                  
                                          
    15
    a.setName("b");
    Preondition Violations
    Unmatched statement a.setName("b"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    15
    a.setName("b");
    15
    address.getSuites().clear();
                                                                    
    16
    s.saveOrUpdate(address);
    16
    s.saveOrUpdate(address);
    Preondition Violations
    Unmatched statement s.saveOrUpdate(address); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                            
                                                                                          
    21
    String hql = "from " + A.class.getName();
                                                                  
    22
    Query q = s.createQuery(hql);
    Preondition Violations
    Unmatched statement Query q=s.createQuery(hql); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    22
    Query q = s.createQuery(hql);
                              
    23
    q.list();
    Preondition Violations
    Unmatched statement q.list(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    23
    q.list();
    17
    t.commit();
    17
    t.commit();
    24
    tx.commit();
    Differences
    Expression1Expression2Difference
    ttxVARIABLE_NAME_MISMATCH
    24
    tx.commit();
    18
    s.close();
    17
    s.close();
    19
    s = openSession();
    19
    s = openSession();
    19
    s = sf.openSession();
    Differences
    Expression1Expression2Difference
    sfMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19
    s = sf.openSession();
    20
    t = s.beginTransaction();
    20
    t = s.beginTransaction();
    20
    tx = s.beginTransaction();
    Differences
    Expression1Expression2Difference
    ttxVARIABLE_NAME_MISMATCH
    20
    tx = s.beginTransaction();
    21
    Long count = (Long)s.createQuery("select count(*) from Suite").list().get(0);
    21
    Long count = (Long)s.createQuery("select count(*) from Suite").list().get(0);
    Preondition Violations
    Unmatched statement Long count=(Long)s.createQuery("select count(*) from Suite").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                  
    22
    assertEquals("all-delete-orphan not cascaded properly to cleared persistent collection entities", 0, count.longValue());
    22
    assertEquals("all-delete-orphan not cascaded properly to cleared persistent collection entities", 0, count.longValue());
    18
    assertEquals(1, stats.getFlushCount());
    Differences
    Expression1Expression2Difference
    assertEquals("all-delete-orphan not cascaded properly to cleared persistent collection entities",0,count.longValue())assertEquals(1,stats.getFlushCount())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals("all-delete-orphan not cascaded properly to cleared persistent collection entities",0,count.longValue()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(1,stats.getFlushCount()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("all-delete-orphan not cascaded properly to cleared persistent collection entities",0,count.longValue()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,stats.getFlushCount()) is a void method call, and thus it cannot be parameterized
    18
    assertEquals(1, stats.getFlushCount());
    23
    count = (Long)s.createQuery("select count(*) from Note").list().get(0);
    23
    count = (Long)s.createQuery("select count(*) from Note").list().get(0);
    Preondition Violations
    Unmatched statement count=(Long)s.createQuery("select count(*) from Note").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                      
    24
    assertEquals(0, count.longValue());
                                                                                
    25
    s.delete(address);
    25
    s.delete(address);
    Preondition Violations
    Unmatched statement s.delete(address); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                
                                                                                                          
    26
    assertEquals(1, stats.getQueryExecutionCount());
    26
    t.commit();
    26
    t.commit();
    Preondition Violations
    Unmatched statement t.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                  
    27
    s.close();
    25
    s.close();
                                                                                                                                                
    27
    assertEquals(1, stats.getQueryStatistics(hql).getExecutionCount());
                                                                                    
    28
    stats.setStatisticsEnabled(isStats);
    Preondition Violations
    Unmatched statement stats.setStatisticsEnabled(isStats); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    28
    stats.setStatisticsEnabled(isStats);
    Precondition Violations (29)
    Row Violation
    1Unmatched statement Statistics stats=sf.getStatistics(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement stats.clear(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Unmatched statement address.setInfo("123 Main St."); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    6Unmatched statement stats.setStatisticsEnabled(true); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    7Unmatched statement s.save(address); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Unmatched statement a.setName("mya"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    12Unmatched statement note.setDescription("a description"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    13Unmatched statement s.save(a); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14Unmatched statement a.setName("b"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    15Unmatched statement s.saveOrUpdate(address); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16Unmatched statement Query q=s.createQuery(hql); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17Unmatched statement q.list(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    18Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    20Unmatched statement Long count=(Long)s.createQuery("select count(*) from Suite").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Expression assertEquals("all-delete-orphan not cascaded properly to cleared persistent collection entities",0,count.longValue()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression assertEquals(1,stats.getFlushCount()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23Expression assertEquals("all-delete-orphan not cascaded properly to cleared persistent collection entities",0,count.longValue()) is a void method call, and thus it cannot be parameterized
    24Expression assertEquals(1,stats.getFlushCount()) is a void method call, and thus it cannot be parameterized
    25Unmatched statement count=(Long)s.createQuery("select count(*) from Note").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    26Unmatched statement s.delete(address); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    27Unmatched statement t.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    28Unmatched statement stats.setStatisticsEnabled(isStats); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    29Clone fragment #1 returns variables s, t , while Clone fragment #2 returns variables s