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 s = openSession(); Transaction tx = s.beginTransaction(); NumberedNode root = new NumberedNode( "root" ); s.saveOrUpdate( root ); tx.commit(); tx = s.beginTransaction(); NumberedNode child = new NumberedNode( "child" ); root.addChild( child ); s.saveOrUpdate( root ); assertFalse( s.contains( child ) ); s.flush(); assertTrue( s.contains( child ) ); tx.commit(); assertTrue( root.getChildren().contains( child ) ); assertEquals( root.getChildren().size(), 1 ); tx = s.beginTransaction(); assertEquals( s.createCriteria( NumberedNode.class ) .setProjection( Projections.rowCount() ) .uniqueResult(), new Integer( 2 ) ); s.delete( root ); s.delete( child ); tx.commit(); s.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/ops/SaveOrUpdateTest.java
Method name: void testImplicitSelectEntityAssociationInShallowQuery() Method name: void testSaveOrUpdateManaged()
Number of AST nodes: 25 Number of AST nodes: 21
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		Transaction tx = s.beginTransaction();
3
		SimpleEntityWithAssociation owner = new SimpleEntityWithAssociation( "owner" );
3
		
4
		SimpleAssociatedEntity e1 = new SimpleAssociatedEntity( "thing one", owner );
5
		SimpleAssociatedEntity e2 = new SimpleAssociatedEntity
4
NumberedNode root = new NumberedNode( "root" );
5
		s.saveOrUpdate( root );
6
		tx.commit();
7
		tx = s.beginTransaction();
6
( "thing two" );
8
		NumberedNode child = new NumberedNode( "child" );
7
		s.save( e1 );
9
		
8
		s.save( e2 );
9
		s.save( owner );
10
		s.getTransaction().commit(
10
root.addChild( child );
11
		s.saveOrUpdate( root );
11
);
12
		assertFalse( s.contains( child ) );
12
		s.close();
13
		s.flush();
13
	 	s = openSession();
14
	
14
		s.beginTransaction();
15
		int count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).list().iterator() );
16
		assertEquals( 1, count ); // thing two would be removed from the result due to the inner join
17
		count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).iterate() 
15
	assertTrue( s.contains( child ) );
16
		tx.commit();
17
		assertTrue( root.getChildren().contains( child ) );
18
		assertEquals( root.getChildren().size(), 1 );
18
);
19
		tx = s.beginTransaction();
19
		assertEquals( 1, count );
20
		assertEquals(
20
		s.getTransaction().commit();
21
		s.close();
22
	 	s = openSession();
23
		s.beginTransaction
21
				s.createCriteria( NumberedNode.class )
22
						.setProjection( Projections.rowCount() )
24
();
23
						.uniqueResult(),
25
		s.delete( e1 
24
		        new Integer( 2 )
26
);
25
		);
27
		s.delete( e2 );
26
		s.delete( root );
28
		s.delete( owner );
27
		s.delete( child );
29
		s.getTransaction().commit();
28
		tx.commit();
30
		s.close();
29
		s.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 comparisons525
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements6
    Number of unmapped statements in the first code fragment19
    Number of unmapped statements in the second code fragment15
    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();
                                                                                  
    2
    Transaction tx = s.beginTransaction();
    Preondition Violations
    Unmatched statement Transaction tx=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2
    Transaction tx = s.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
    NumberedNode root = new NumberedNode("root");
    Preondition Violations
    Unmatched statement NumberedNode root=new NumberedNode("root"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3
    NumberedNode root = new NumberedNode("root");
    3
    SimpleEntityWithAssociation owner = new SimpleEntityWithAssociation("owner");
    3
    SimpleEntityWithAssociation owner = new SimpleEntityWithAssociation("owner");
    Preondition Violations
    Unmatched statement SimpleEntityWithAssociation owner=new SimpleEntityWithAssociation("owner"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                                                                                
                                                    
    4
    s.saveOrUpdate(root);
    Preondition Violations
    Unmatched statement s.saveOrUpdate(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4
    s.saveOrUpdate(root);
    4
    SimpleAssociatedEntity e1 = new SimpleAssociatedEntity("thing one", owner);
    4
    SimpleAssociatedEntity e1 = new SimpleAssociatedEntity("thing one", owner);
    Preondition Violations
    Unmatched statement SimpleAssociatedEntity e1=new SimpleAssociatedEntity("thing one",owner); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                                                                          
    5
    SimpleAssociatedEntity e2 = new SimpleAssociatedEntity("thing two");
    5
    SimpleAssociatedEntity e2 = new SimpleAssociatedEntity("thing two");
    Preondition Violations
    Unmatched statement SimpleAssociatedEntity e2=new SimpleAssociatedEntity("thing two"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                                                              
                                                          
    6
    tx = s.beginTransaction();
    Preondition Violations
    Unmatched statement tx=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6
    tx = s.beginTransaction();
    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
    NumberedNode child = new NumberedNode("child");
    Preondition Violations
    Unmatched statement NumberedNode child=new NumberedNode("child"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    7
    NumberedNode child = new NumberedNode("child");
    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
    root.addChild(child);
    Preondition Violations
    Unmatched statement root.addChild(child); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    8
    root.addChild(child);
    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.saveOrUpdate(root);
    Preondition Violations
    Unmatched statement s.saveOrUpdate(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9
    s.saveOrUpdate(root);
    9
    s.getTransaction().commit();
    9
    s.getTransaction().commit();
    Preondition Violations
    Unmatched statement s.getTransaction().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                  
                                                                          
    10
    assertFalse(s.contains(child));
    Preondition Violations
    Unmatched statement assertFalse(s.contains(child)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10
    assertFalse(s.contains(child));
                                
    11
    s.flush();
    Preondition Violations
    Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11
    s.flush();
                                                                        
    12
    assertTrue(s.contains(child));
    Preondition Violations
    Unmatched statement assertTrue(s.contains(child)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    assertTrue(s.contains(child));
                                                            
    16
    tx = s.beginTransaction();
    Preondition Violations
    Unmatched statement tx=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16
    tx = s.beginTransaction();
                                                                                                                                                                                                                                                          
    17
    assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(2));
    Preondition Violations
    Unmatched statement assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(),new Integer(2)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17
    assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(2));
                                          
    18
    s.delete(root);
    Preondition Violations
    Unmatched statement s.delete(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    18
    s.delete(root);
                                            
    19
    s.delete(child);
    Preondition Violations
    Unmatched statement s.delete(child); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19
    s.delete(child);
                                    
    20
    tx.commit();
    Preondition Violations
    Unmatched statement tx.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    20
    tx.commit();
    10
    s.close();
    21
    s.close();
    11
    s = openSession();
    11
    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
                                            
    12
    s.beginTransaction();
                                                      
    13
    int count = determineCount(s.createQuery("select e.id, e.owner from SimpleAssociatedEntity e").list().iterator());
                                                                                                                                                                                                                                            
    14
    assertEquals(1, count);
    14
    assertEquals(1, count);
    14
    assertTrue(root.getChildren().contains(child));
    Differences
    Expression1Expression2Difference
    assertEqualsassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,count)assertTrue(root.getChildren().contains(child))ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(1,count) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(root.getChildren().contains(child)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(root.getChildren().contains(child)) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,count) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(root.getChildren().contains(child)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(root.getChildren().contains(child)) is a void method call, and thus it cannot be parameterized
    14
    assertTrue(root.getChildren().contains(child));
    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);
    15
    assertEquals(root.getChildren().size(), 1);
    Differences
    Expression1Expression2Difference
    1root.getChildren().size()TYPE_COMPATIBLE_REPLACEMENT
    count1TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression root.getChildren().size() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression count cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15
    assertEquals(root.getChildren().size(), 1);
    17
    s.getTransaction().commit();
    17
    s.getTransaction().commit();
    13
    tx.commit();
    Differences
    Expression1Expression2Difference
    s.getTransaction()txTYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression tx cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13
    tx.commit();
    18
    s.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);
                                      
    22
    s.delete(e2);
                                      
    23
    s.delete(owner);
                                            
    24
    s.getTransaction().commit();
    24
    s.getTransaction().commit();
    5
    tx.commit();
    Differences
    Expression1Expression2Difference
    s.getTransaction()txTYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression tx cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5
    tx.commit();
    25
    s.close();
                                
    Precondition Violations (40)
    Row Violation
    1Unmatched statement Transaction tx=s.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 NumberedNode root=new NumberedNode("root"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Unmatched statement SimpleEntityWithAssociation owner=new SimpleEntityWithAssociation("owner"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    5Unmatched statement s.saveOrUpdate(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement SimpleAssociatedEntity e1=new SimpleAssociatedEntity("thing one",owner); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    7Unmatched statement SimpleAssociatedEntity e2=new SimpleAssociatedEntity("thing two"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    8Unmatched statement tx=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9Unmatched statement s.save(e1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Unmatched statement NumberedNode child=new NumberedNode("child"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    11Unmatched statement s.save(e2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Unmatched statement root.addChild(child); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    13Unmatched statement s.save(owner); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14Unmatched statement s.saveOrUpdate(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15Unmatched statement s.getTransaction().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16Unmatched statement assertFalse(s.contains(child)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    18Unmatched statement assertTrue(s.contains(child)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19Unmatched statement tx=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    20Unmatched statement assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(),new Integer(2)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Unmatched statement s.delete(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    22Unmatched statement s.delete(child); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    23Unmatched statement tx.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    24Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    25Expression assertEquals(1,count) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    26Expression assertTrue(root.getChildren().contains(child)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    27Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    28Expression assertTrue(root.getChildren().contains(child)) is a void method call, and thus it cannot be parameterized
    29Expression assertEquals(1,count) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    30Expression assertTrue(root.getChildren().contains(child)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    31Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    32Expression assertTrue(root.getChildren().contains(child)) is a void method call, and thus it cannot be parameterized
    33Unmatched 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
    34Expression root.getChildren().size() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    35Expression count cannot be parameterized, because it has dependencies to/from statements that will be extracted
    36Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    37Expression tx cannot be parameterized, because it has dependencies to/from statements that will be extracted
    38Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    39Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    40Expression tx cannot be parameterized, because it has dependencies to/from statements that will be extracted