Session s = openSession(); s.beginTransaction(); SimpleEntityWithAssociation owner = new SimpleEntityWithAssociation( "owner" ); SimpleAssociatedEntity e1 = new SimpleAssociatedEntity( "thing one", owner ); SimpleAssociatedEntity e2 = new SimpleAssociatedEntity( "thing two" ); s.save( e1 ); s.save( e2 ); s.save( owner ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); int count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).list().iterator() ); assertEquals( 1, count ); // thing two would be removed from the result due to the inner join count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).iterate() ); assertEquals( 1, count ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); s.delete( e1 ); s.delete( e2 ); s.delete( owner ); s.getTransaction().commit(); s.close();
Session session = openSession(); Transaction t = session.beginTransaction(); Product prod = new Product(); prod.setName("Widget"); Part part = new Part(); part.setName("Widge"); part.setDescription("part if a Widget"); prod.getParts().add(part); Part part2 = new Part(); part2.setName("Get"); part2.setDescription("another part if a Widget"); prod.getParts().add(part2); session.persist(prod); session.flush(); prod.getParts().remove(part); t.commit(); session.close(); session = openSession(); t = session.beginTransaction(); assertNull( session.get(Part.class, "Widge") ); assertNotNull( session.get(Part.class, "Get") ); session.delete( session.get(Product.class, "Widget") ); t.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/hql/ASTParserLoadingTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/orphan/OrphanTest.java
Method name: void testImplicitSelectEntityAssociationInShallowQuery() Method name: void testOrphanDeleteAfterPersistAndFlush()
Number of AST nodes: 25 Number of AST nodes: 24
1
Session s = openSession();
1
Session session = openSession();
2
		s.beginTransaction();
2
		
3
		SimpleEntityWithAssociation owner = new SimpleEntityWithAssociation( "owner" );
4
		SimpleAssociatedEntity e1 = new SimpleAssociatedEntity( "thing one", owner );
5
		SimpleAssociatedEntity e2 = new SimpleAssociatedEntity( "thing two" );
6
		s.save( e1 );
7
		s.save( e2 );
8
		s.save( owner );
9
		s.getTransaction().commit();
10
		s.close();
11
	 	s = openSession();
12
		s.beginTransaction();
13
		int count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).list().iterator() );
14
		assertEquals( 1, count ); // thing two would be removed from the result due to the inner join
15
		count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).iterate() );
16
		assertEquals( 1, count );
17
		s.getTransaction()
3
Transaction t = session.beginTransaction();
4
		Product prod = new Product();
5
		prod.setName("Widget");
6
		Part part = new Part();
7
		part.setName("Widge");
8
		part.setDescription("part if a Widget");
9
		prod.getParts().add(part);
10
		Part part2 = new Part();
11
		part2.setName("Get");
12
		part2.setDescription("another part if a Widget");
13
		prod.getParts().add(part2);
14
		session.persist(prod);
15
		session.flush();
16
		
17
		prod.getParts().remove(part);
18
		
18
.commit();
19
		t.commit();
19
		s.close();
20
		session.close();
21
		
20
	 	s = openSession();
22
		session = openSession();
21
		s.beginTransaction();
23
		t = session.beginTransaction();
22
		s.delete( e1 );
24
		
23
		s.delete( e2
25
assertNull( session.get(Part.class, "Widge") );
24
 );
26
		assertNotNull( session.get(Part.class, "Get") );
25
		s.delete( owner );
27
		session.delete( 
26
		s.getTransaction()
28
session.get(Product.class, "Widget") );
27
.commit();
29
		t.commit();
28
		s.close();
30
		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 comparisons600
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements10
    Number of unmapped statements in the first code fragment15
    Number of unmapped statements in the second code fragment14
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
    1
    Session session = openSession();
    Differences
    Expression1Expression2Difference
    ssessionVARIABLE_NAME_MISMATCH
    1
    Session session = openSession();
                                                                                            
    2
    Transaction t = session.beginTransaction();
    Preondition Violations
    Unmatched statement Transaction t=session.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2
    Transaction t = session.beginTransaction();
    2
    s.beginTransaction();
    2
    s.beginTransaction();
    Preondition Violations
    Unmatched statement s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                    
                                                                
    3
    Product prod = new Product();
    3
    SimpleEntityWithAssociation owner = new SimpleEntityWithAssociation("owner");
                                                                                                                                                                
    4
    SimpleAssociatedEntity e1 = new SimpleAssociatedEntity("thing one", owner);
                                                                                                                                                          
    5
    SimpleAssociatedEntity e2 = new SimpleAssociatedEntity("thing two");
                                                                                                                                              
    6
    s.save(e1);
    6
    s.save(e1);
    Preondition Violations
    Unmatched statement s.save(e1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                
    7
    s.save(e2);
    7
    s.save(e2);
    Preondition Violations
    Unmatched statement s.save(e2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                
    8
    s.save(owner);
    8
    s.save(owner);
    Preondition Violations
    Unmatched statement s.save(owner); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                      
    9
    s.getTransaction().commit();
    9
    s.getTransaction().commit();
    16
    t.commit();
    Differences
    Expression1Expression2Difference
    s.getTransaction()tTYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16
    t.commit();
    10
    s.close();
    10
    s.close();
    17
    session.close();
    Differences
    Expression1Expression2Difference
    ssessionVARIABLE_NAME_MISMATCH
    17
    session.close();
    11
    s = openSession();
    11
    s = openSession();
    18
    session = openSession();
    Differences
    Expression1Expression2Difference
    ssessionVARIABLE_NAME_MISMATCH
    18
    session = openSession();
    12
    s.beginTransaction();
                                                      
    13
    int count = determineCount(s.createQuery("select e.id, e.owner from SimpleAssociatedEntity e").list().iterator());
    13
    int count = determineCount(s.createQuery("select e.id, e.owner from SimpleAssociatedEntity e").list().iterator());
    Preondition Violations
    Unmatched statement int count=determineCount(s.createQuery("select e.id, e.owner from SimpleAssociatedEntity e").list().iterator()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                                                            
    14
    assertEquals(1, count);
    14
    assertEquals(1, count);
    6
    part.setName("Widge");
    Differences
    Expression1Expression2Difference
    assertEqualssetNameMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,count)part.setName("Widge")ARGUMENT_NUMBER_MISMATCH
    partMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    Expression part.setName("Widge") is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    Expression part.setName("Widge") is a void method call, and thus it cannot be parameterized
    6
    part.setName("Widge");
    15
    count = determineCount(s.createQuery("select e.id, e.owner from SimpleAssociatedEntity e").iterate());
    15
    count = determineCount(s.createQuery("select e.id, e.owner from SimpleAssociatedEntity e").iterate());
    Preondition Violations
    Unmatched statement count=determineCount(s.createQuery("select e.id, e.owner from SimpleAssociatedEntity e").iterate()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                                    
    16
    assertEquals(1, count);
    16
    assertEquals(1, count);
    4
    prod.setName("Widget");
    Differences
    Expression1Expression2Difference
    assertEqualssetNameMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,count)prod.setName("Widget")ARGUMENT_NUMBER_MISMATCH
    prodMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    Expression prod.setName("Widget") is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    Expression prod.setName("Widget") is a void method call, and thus it cannot be parameterized
    4
    prod.setName("Widget");
                                                    
    5
    Part part = new Part();
                                                                                          
    7
    part.setDescription("part if a Widget");
                                                              
    8
    prod.getParts().add(part);
                                                      
    9
    Part part2 = new Part();
                                                      
    10
    part2.setName("Get");
                                                                                                              
    11
    part2.setDescription("another part if a Widget");
                                                                  
    12
    prod.getParts().add(part2);
                                                        
    13
    session.persist(prod);
    Preondition Violations
    Unmatched statement session.persist(prod); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13
    session.persist(prod);
    17
    s.getTransaction().commit();
    17
    s.getTransaction().commit();
    20
    assertNull(session.get(Part.class, "Widge"));
    Differences
    Expression1Expression2Difference
    commitassertNullMETHOD_INVOCATION_NAME_MISMATCH
    s.getTransaction().commit()assertNull(session.get(Part.class,"Widge"))ARGUMENT_NUMBER_MISMATCH
    s.getTransaction()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(session.get(Part.class,"Widge")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    Expression assertNull(session.get(Part.class,"Widge")) is a void method call, and thus it cannot be parameterized
    Expression s.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(session.get(Part.class,"Widge")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    Expression assertNull(session.get(Part.class,"Widge")) is a void method call, and thus it cannot be parameterized
    20
    assertNull(session.get(Part.class, "Widge"));
    18
    s.close();
    18
    s.close();
    24
    session.close();
    Differences
    Expression1Expression2Difference
    ssessionVARIABLE_NAME_MISMATCH
    24
    session.close();
    19
    s = openSession();
    19
    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
                                            
    20
    s.beginTransaction();
                                                      
    21
    s.delete(e1);
    21
    s.delete(e1);
    14
    session.flush();
    Differences
    Expression1Expression2Difference
    deleteflushMETHOD_INVOCATION_NAME_MISMATCH
    ssessionVARIABLE_NAME_MISMATCH
    s.delete(e1)session.flush()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(e1) 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.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(e1) 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
    14
    session.flush();
                                                                      
    15
    prod.getParts().remove(part);
                                                                      
    19
    t = session.beginTransaction();
    Preondition Violations
    Unmatched statement t=session.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19
    t = session.beginTransaction();
                                                                                                                    
    22
    session.delete(session.get(Product.class, "Widget"));
    22
    s.delete(e2);
                                      
                                  
    23
    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
    23
    t.commit();
    23
    s.delete(owner);
                                            
    24
    s.getTransaction().commit();
    24
    s.getTransaction().commit();
    21
    assertNotNull(session.get(Part.class, "Get"));
    Differences
    Expression1Expression2Difference
    commitassertNotNullMETHOD_INVOCATION_NAME_MISMATCH
    s.getTransaction().commit()assertNotNull(session.get(Part.class,"Get"))ARGUMENT_NUMBER_MISMATCH
    s.getTransaction()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertNotNull(session.get(Part.class,"Get")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(session.get(Part.class,"Get")) is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(session.get(Part.class,"Get")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(session.get(Part.class,"Get")) is a void method call, and thus it cannot be parameterized
    21
    assertNotNull(session.get(Part.class, "Get"));
    25
    s.close();
                                
    Precondition Violations (40)
    Row Violation
    1Unmatched statement Transaction t=session.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement s.save(e1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement s.save(e2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement s.save(owner); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Unmatched statement int count=determineCount(s.createQuery("select e.id, e.owner from SimpleAssociatedEntity e").list().iterator()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    9Expression part.setName("Widge") is a void method call, and thus it cannot be parameterized
    10Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    11Expression part.setName("Widge") is a void method call, and thus it cannot be parameterized
    12Unmatched statement count=determineCount(s.createQuery("select e.id, e.owner from SimpleAssociatedEntity e").iterate()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    14Expression prod.setName("Widget") is a void method call, and thus it cannot be parameterized
    15Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    16Expression prod.setName("Widget") is a void method call, and thus it cannot be parameterized
    17Unmatched statement session.persist(prod); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    18Expression s.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19Expression assertNull(session.get(Part.class,"Widge")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    20Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    21Expression assertNull(session.get(Part.class,"Widge")) is a void method call, and thus it cannot be parameterized
    22Expression s.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23Expression assertNull(session.get(Part.class,"Widge")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    24Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    25Expression assertNull(session.get(Part.class,"Widge")) is a void method call, and thus it cannot be parameterized
    26Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    27Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    28Expression s.delete(e1) is a void method call, and thus it cannot be parameterized
    29Expression session.flush() is a void method call, and thus it cannot be parameterized
    30Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    31Expression s.delete(e1) is a void method call, and thus it cannot be parameterized
    32Expression session.flush() is a void method call, and thus it cannot be parameterized
    33Unmatched statement t=session.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    34Unmatched statement t.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    35Expression assertNotNull(session.get(Part.class,"Get")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    36Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    37Expression assertNotNull(session.get(Part.class,"Get")) is a void method call, and thus it cannot be parameterized
    38Expression assertNotNull(session.get(Part.class,"Get")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    39Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    40Expression assertNotNull(session.get(Part.class,"Get")) is a void method call, and thus it cannot be parameterized