Session session = openSession(); Transaction txn = session.beginTransaction(); Mammal m1 = new Mammal(); m1.setBodyWeight( 11f ); m1.setDescription( "Mammal #1" ); session.save( m1 ); Mammal m2 = new Mammal(); m2.setBodyWeight( 9f ); m2.setDescription( "Mammal #2" ); m2.setMother( m1 ); session.save( m2 ); txn.commit(); session.close(); createdAnimalIds.add( m1.getId() ); createdAnimalIds.add( m2.getId() );
Session s = openSession(); s.beginTransaction(); Item item = new Item(); item.setName( "dummy" ); s.persist( item ); s.getTransaction().commit(); s.close(); Long id = item.getId(); s = openSession(); s.beginTransaction(); s.delete( item ); item = ( Item ) s.get( Item.class, id ); s.getTransaction().commit(); s.close(); assertNull( "expecting removed entity to be returned as null from get()", item );
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/jpa/removed/RemovedEntityTest.java
Method name: void createTestBaseData() Method name: void testRemoveThenGet()
Number of AST nodes: 15 Number of AST nodes: 15
1
Session session = openSession();
1
Session s = openSession();
2
		Transaction txn = session.beginTransaction();
2
		s.beginTransaction();
3

3
		Mammal m1 = new Mammal();
4
		Item item = new Item();
4
		m1.setBodyWeight( 11f
5
		item.setName( "dummy" );
5
 );
6
		s.persist( item );
6
		m1.setDescription( "Mammal #1" );
7
		s.getTransaction().commit();
8

7
		session.save( m1 );
9
		s
8
		Mammal m2 = new Mammal();
9
		m2.setBodyWeight( 9f 
10
.close();
11
		Long id = item.getId();
10
);
12
		s = openSession();
11
		m2.setDescription( "Mammal #2" );
13
		s.beginTransaction();
12
		m2.setMother( m1 );
14
		s.delete( item );
15

13
		session.save( m2 );
16
		item = ( Item ) s.get( Item.class, id );
17

14
		txn.commit();
18
		s.getTransaction().commit();
15
		session.close();
19
		s.close();
16
		createdAnimalIds.add( m1.getId() );
17
		createdAnimalIds.add( m2.getId()
18
 );
20
		assertNull( "expecting removed entity to be returned as null from get()", item );
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 comparisons225
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements4
    Number of unmapped statements in the first code fragment11
    Number of unmapped statements in the second code fragment11
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    Session session = openSession();
    1
    Session session = openSession();
    1
    Session s = openSession();
    Differences
    Expression1Expression2Difference
    sessionsVARIABLE_NAME_MISMATCH
    1
    Session s = openSession();
                                                    
    2
    s.beginTransaction();
    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
    Item item = new Item();
    3
    Mammal m1 = new Mammal();
                                                        
                                                      
    4
    item.setName("dummy");
                                          
    5
    s.persist(item);
                                                                  
    6
    s.getTransaction().commit();
    4
    m1.setBodyWeight(11f);
    4
    m1.setBodyWeight(11f);
    15
    assertNull("expecting removed entity to be returned as null from get()", item);
    Differences
    Expression1Expression2Difference
    setBodyWeightassertNullMETHOD_INVOCATION_NAME_MISMATCH
    m1.setBodyWeight(11f)assertNull("expecting removed entity to be returned as null from get()",item)ARGUMENT_NUMBER_MISMATCH
    m1MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression m1.setBodyWeight(11f) is a void method call, and thus it cannot be parameterized
    Expression assertNull("expecting removed entity to be returned as null from get()",item) is a void method call, and thus it cannot be parameterized
    Expression m1.setBodyWeight(11f) is a void method call, and thus it cannot be parameterized
    Expression assertNull("expecting removed entity to be returned as null from get()",item) is a void method call, and thus it cannot be parameterized
    15
    assertNull("expecting removed entity to be returned as null from get()", item);
    5
    m1.setDescription("Mammal #1");
                                                                        
    6
    session.save(m1);
                                            
    7
    Mammal m2 = new Mammal();
                                                        
                                                    
    8
    Long id = item.getId();
    8
    m2.setBodyWeight(9f);
                                                    
                                          
    9
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9
    s = openSession();
    9
    m2.setDescription("Mammal #2");
                                                                        
                                                      
    10
    s.beginTransaction();
    10
    m2.setMother(m1);
                                              
                                          
    11
    s.delete(item);
    11
    session.save(m2);
                                              
                                                                            
    12
    item = (Item)s.get(Item.class, id);
    12
    txn.commit();
    12
    txn.commit();
    13
    s.getTransaction().commit();
    Differences
    Expression1Expression2Difference
    txns.getTransaction()TYPE_COMPATIBLE_REPLACEMENT
    13
    s.getTransaction().commit();
    13
    session.close();
    13
    session.close();
    7
    s.close();
    Differences
    Expression1Expression2Difference
    sessionsVARIABLE_NAME_MISMATCH
    7
    s.close();
                                
    14
    s.close();
    14
    createdAnimalIds.add(m1.getId());
                                                                              
    15
    createdAnimalIds.add(m2.getId());
                                                                              
    Precondition Violations (6)
    Row Violation
    1Unmatched 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
    2Expression m1.setBodyWeight(11f) is a void method call, and thus it cannot be parameterized
    3Expression assertNull("expecting removed entity to be returned as null from get()",item) is a void method call, and thus it cannot be parameterized
    4Expression m1.setBodyWeight(11f) is a void method call, and thus it cannot be parameterized
    5Expression assertNull("expecting removed entity to be returned as null from get()",item) is a void method call, and thus it cannot be parameterized
    6Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted