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 statements17
    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
    SessionFactory sf = getSessions();
                                                                                  
    2
    Statistics stats = sf.getStatistics();
                                                                                                  
    3
    boolean isStats = stats.isStatisticsEnabled();
                                      
    4
    stats.clear();
                                                                            
    5
    stats.setStatisticsEnabled(true);
    1
    Session s = openSession();
    1
    Session s = openSession();
    6
    Session s = sf.openSession();
    Differences
    Expression1Expression2Difference
    sfMISSING_METHOD_INVOCATION_EXPRESSION
    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.");
    7
    assertEquals(1, stats.getSessionOpenCount());
    Differences
    Expression1Expression2Difference
    setInfoassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    address.setInfo("123 Main St.")assertEquals(1,stats.getSessionOpenCount())ARGUMENT_NUMBER_MISMATCH
    addressMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression address.setInfo("123 Main St.") is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,stats.getSessionOpenCount()) is a void method call, and thus it cannot be parameterized
    Expression address.setInfo("123 Main St.") is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,stats.getSessionOpenCount()) is a void method call, and thus it cannot be parameterized
    7
    assertEquals(1, stats.getSessionOpenCount());
    5
    Suite suite = new Suite();
                                                          
    6
    address.getSuites().add(suite);
                                                                        
                                    
    12
    A a = new A();
                                              
    13
    a.setName("mya");
    7
    s.save(address);
    7
    s.save(address);
    14
    s.save(a);
    Differences
    Expression1Expression2Difference
    addressaVARIABLE_NAME_MISMATCH
    org.hibernate.test.deletetransient.Addressorg.hibernate.test.legacy.AVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.deletetransient.Address of variable address does not match with type org.hibernate.test.legacy.A of variable a
    • Make classes org.hibernate.test.deletetransient.Address and org.hibernate.test.legacy.A extend a common superclass
    14
    s.save(a);
                                          
    15
    a.setName("b");
    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
    Note note = new Note();
                                                      
    13
    note.setDescription("a description");
    13
    note.setDescription("a description");
    9
    assertEquals(1, stats.getSessionCloseCount());
    Differences
    Expression1Expression2Difference
    setDescriptionassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    note.setDescription("a description")assertEquals(1,stats.getSessionCloseCount())ARGUMENT_NUMBER_MISMATCH
    noteMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression note.setDescription("a description") is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,stats.getSessionCloseCount()) is a void method call, and thus it cannot be parameterized
    Expression note.setDescription("a description") is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,stats.getSessionCloseCount()) is a void method call, and thus it cannot be parameterized
    9
    assertEquals(1, stats.getSessionCloseCount());
    14
    suite.getNotes().add(note);
                                                                  
                                                                                          
    21
    String hql = "from " + A.class.getName();
                                                                  
    22
    Query q = s.createQuery(hql);
                              
    23
    q.list();
    15
    address.getSuites().clear();
    15
    address.getSuites().clear();
    27
    assertEquals(1, stats.getQueryStatistics(hql).getExecutionCount());
    Differences
    Expression1Expression2Difference
    clearassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    address.getSuites().clear()assertEquals(1,stats.getQueryStatistics(hql).getExecutionCount())ARGUMENT_NUMBER_MISMATCH
    address.getSuites()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression address.getSuites().clear() is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,stats.getQueryStatistics(hql).getExecutionCount()) is a void method call, and thus it cannot be parameterized
    Expression address.getSuites().clear() is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,stats.getQueryStatistics(hql).getExecutionCount()) is a void method call, and thus it cannot be parameterized
    27
    assertEquals(1, stats.getQueryStatistics(hql).getExecutionCount());
    16
    s.saveOrUpdate(address);
    16
    s.saveOrUpdate(address);
    18
    assertEquals(1, stats.getFlushCount());
    Differences
    Expression1Expression2Difference
    saveOrUpdateassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    s.saveOrUpdate(address)assertEquals(1,stats.getFlushCount())ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.saveOrUpdate(address) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.saveOrUpdate(address) 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
    Expression s.saveOrUpdate(address) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.saveOrUpdate(address) 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());
    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());
    26
    assertEquals(1, stats.getQueryExecutionCount());
    Differences
    Expression1Expression2Difference
    assertEquals("all-delete-orphan not cascaded properly to cleared persistent collection entities",0,count.longValue())assertEquals(1,stats.getQueryExecutionCount())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    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.getQueryExecutionCount()) is a void method call, and thus it cannot be parameterized
    26
    assertEquals(1, stats.getQueryExecutionCount());
    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());
    24
    assertEquals(0, count.longValue());
    28
    stats.setStatisticsEnabled(isStats);
    Differences
    Expression1Expression2Difference
    assertEqualssetStatisticsEnabledMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(0,count.longValue())stats.setStatisticsEnabled(isStats)ARGUMENT_NUMBER_MISMATCH
    statsMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals(0,count.longValue()) is a void method call, and thus it cannot be parameterized
    Expression stats.setStatisticsEnabled(isStats) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(0,count.longValue()) is a void method call, and thus it cannot be parameterized
    Expression stats.setStatisticsEnabled(isStats) is a void method call, and thus it cannot be parameterized
    28
    stats.setStatisticsEnabled(isStats);
    25
    s.delete(address);
                                                
    26
    t.commit();
                                  
    27
    s.close();
    25
    s.close();
    Precondition Violations (33)
    Row Violation
    1Expression address.setInfo("123 Main St.") is a void method call, and thus it cannot be parameterized
    2Expression assertEquals(1,stats.getSessionOpenCount()) is a void method call, and thus it cannot be parameterized
    3Expression address.setInfo("123 Main St.") is a void method call, and thus it cannot be parameterized
    4Expression assertEquals(1,stats.getSessionOpenCount()) is a void method call, and thus it cannot be parameterized
    5Type org.hibernate.test.deletetransient.Address of variable address does not match with type org.hibernate.test.legacy.A of variable a
    6Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9Expression note.setDescription("a description") is a void method call, and thus it cannot be parameterized
    10Expression assertEquals(1,stats.getSessionCloseCount()) is a void method call, and thus it cannot be parameterized
    11Expression note.setDescription("a description") is a void method call, and thus it cannot be parameterized
    12Expression assertEquals(1,stats.getSessionCloseCount()) is a void method call, and thus it cannot be parameterized
    13Expression address.getSuites().clear() is a void method call, and thus it cannot be parameterized
    14Expression assertEquals(1,stats.getQueryStatistics(hql).getExecutionCount()) is a void method call, and thus it cannot be parameterized
    15Expression address.getSuites().clear() is a void method call, and thus it cannot be parameterized
    16Expression assertEquals(1,stats.getQueryStatistics(hql).getExecutionCount()) is a void method call, and thus it cannot be parameterized
    17Expression s.saveOrUpdate(address) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression s.saveOrUpdate(address) is a void method call, and thus it cannot be parameterized
    19Expression assertEquals(1,stats.getFlushCount()) is a void method call, and thus it cannot be parameterized
    20Expression s.saveOrUpdate(address) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21Expression s.saveOrUpdate(address) is a void method call, and thus it cannot be parameterized
    22Expression assertEquals(1,stats.getFlushCount()) is a void method call, and thus it cannot be parameterized
    23Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    24Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Unmatched 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
    26Expression 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
    27Expression assertEquals(1,stats.getQueryExecutionCount()) is a void method call, and thus it cannot be parameterized
    28Unmatched 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
    29Expression assertEquals(0,count.longValue()) is a void method call, and thus it cannot be parameterized
    30Expression stats.setStatisticsEnabled(isStats) is a void method call, and thus it cannot be parameterized
    31Expression assertEquals(0,count.longValue()) is a void method call, and thus it cannot be parameterized
    32Expression stats.setStatisticsEnabled(isStats) is a void method call, and thus it cannot be parameterized
    33Clone fragment #1 returns variables t, s , while Clone fragment #2 returns variables s