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 statements10
    Number of unmapped statements in the first code fragment15
    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
    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();
                                                    
                                                                                                
    3
    NumberedNode root = new NumberedNode("root");
    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();
    9
    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
    5
    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);
    9
    s.saveOrUpdate(root);
    Differences
    Expression1Expression2Difference
    assertEqualssaveOrUpdateMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,count)s.saveOrUpdate(root)ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.saveOrUpdate(root) 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 s.saveOrUpdate(root) is a void method call, and thus it cannot be parameterized
    Expression s.saveOrUpdate(root) 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 s.saveOrUpdate(root) is a void method call, and thus it cannot be parameterized
    9
    s.saveOrUpdate(root);
    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
    s.saveOrUpdate(root);
    Differences
    Expression1Expression2Difference
    assertEqualssaveOrUpdateMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,count)s.saveOrUpdate(root)ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.saveOrUpdate(root) 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 s.saveOrUpdate(root) is a void method call, and thus it cannot be parameterized
    Expression s.saveOrUpdate(root) 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 s.saveOrUpdate(root) is a void method call, and thus it cannot be parameterized
    4
    s.saveOrUpdate(root);
                                                          
    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();
                                                                                                    
    7
    NumberedNode child = new NumberedNode("child");
                                                    
    8
    root.addChild(child);
    17
    s.getTransaction().commit();
    17
    s.getTransaction().commit();
    12
    assertTrue(s.contains(child));
    Differences
    Expression1Expression2Difference
    commitassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    s.getTransaction().commit()assertTrue(s.contains(child))ARGUMENT_NUMBER_MISMATCH
    s.getTransaction()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertTrue(s.contains(child)) 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 assertTrue(s.contains(child)) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(s.contains(child)) 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 assertTrue(s.contains(child)) is a void method call, and thus it cannot be parameterized
    12
    assertTrue(s.contains(child));
                                    
    13
    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
    13
    tx.commit();
                                                                                                          
    14
    assertTrue(root.getChildren().contains(child));
                                                            
    16
    tx = s.beginTransaction();
    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);
    21
    s.delete(e1);
    17
    assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(2));
    Differences
    Expression1Expression2Difference
    deleteassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    s.delete(e1)assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(),new Integer(2))ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(),new Integer(2)) 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 assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(),new Integer(2)) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(),new Integer(2)) 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 assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(),new Integer(2)) is a void method call, and thus it cannot be parameterized
    17
    assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(2));
    22
    s.delete(e2);
    22
    s.delete(e2);
    15
    assertEquals(root.getChildren().size(), 1);
    Differences
    Expression1Expression2Difference
    deleteassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    s.delete(e2)assertEquals(root.getChildren().size(),1)ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.delete(e2) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(root.getChildren().size(),1) is a void method call, and thus it cannot be parameterized
    Expression s.delete(e2) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(root.getChildren().size(),1) is a void method call, and thus it cannot be parameterized
    15
    assertEquals(root.getChildren().size(), 1);
    23
    s.delete(owner);
    23
    s.delete(owner);
    11
    s.flush();
    Differences
    Expression1Expression2Difference
    deleteflushMETHOD_INVOCATION_NAME_MISMATCH
    s.delete(owner)s.flush()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(owner) is a void method call, and thus it cannot be parameterized
    Expression s.flush() is a void method call, and thus it cannot be parameterized
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(owner) is a void method call, and thus it cannot be parameterized
    Expression s.flush() is a void method call, and thus it cannot be parameterized
    11
    s.flush();
    24
    s.getTransaction().commit();
    24
    s.getTransaction().commit();
    10
    assertFalse(s.contains(child));
    Differences
    Expression1Expression2Difference
    commitassertFalseMETHOD_INVOCATION_NAME_MISMATCH
    s.getTransaction().commit()assertFalse(s.contains(child))ARGUMENT_NUMBER_MISMATCH
    s.getTransaction()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertFalse(s.contains(child)) 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 assertFalse(s.contains(child)) is a void method call, and thus it cannot be parameterized
    Expression assertFalse(s.contains(child)) 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 assertFalse(s.contains(child)) is a void method call, and thus it cannot be parameterized
    10
    assertFalse(s.contains(child));
                                          
    18
    s.delete(root);
                                            
    19
    s.delete(child);
                                    
    20
    tx.commit();
    25
    s.close();
                                
    Precondition Violations (47)
    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
    2Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Expression s.saveOrUpdate(root) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    6Expression s.saveOrUpdate(root) is a void method call, and thus it cannot be parameterized
    7Expression s.saveOrUpdate(root) cannot be parameterized, 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 s.saveOrUpdate(root) is a void method call, and thus it cannot be parameterized
    10Unmatched 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
    11Expression s.saveOrUpdate(root) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    13Expression s.saveOrUpdate(root) is a void method call, and thus it cannot be parameterized
    14Expression s.saveOrUpdate(root) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression assertEquals(1,count) is a void method call, and thus it cannot be parameterized
    16Expression s.saveOrUpdate(root) is a void method call, and thus it cannot be parameterized
    17Unmatched statement tx=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    18Expression assertTrue(s.contains(child)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    20Expression assertTrue(s.contains(child)) is a void method call, and thus it cannot be parameterized
    21Expression assertTrue(s.contains(child)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    23Expression assertTrue(s.contains(child)) is a void method call, and thus it cannot be parameterized
    24Unmatched statement tx.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    25Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    26Expression assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(),new Integer(2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    27Expression s.delete(e1) is a void method call, and thus it cannot be parameterized
    28Expression assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(),new Integer(2)) is a void method call, and thus it cannot be parameterized
    29Expression assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(),new Integer(2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    30Expression s.delete(e1) is a void method call, and thus it cannot be parameterized
    31Expression assertEquals(s.createCriteria(NumberedNode.class).setProjection(Projections.rowCount()).uniqueResult(),new Integer(2)) is a void method call, and thus it cannot be parameterized
    32Expression s.delete(e2) is a void method call, and thus it cannot be parameterized
    33Expression assertEquals(root.getChildren().size(),1) is a void method call, and thus it cannot be parameterized
    34Expression s.delete(e2) is a void method call, and thus it cannot be parameterized
    35Expression assertEquals(root.getChildren().size(),1) is a void method call, and thus it cannot be parameterized
    36Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    37Expression s.delete(owner) is a void method call, and thus it cannot be parameterized
    38Expression s.flush() is a void method call, and thus it cannot be parameterized
    39Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    40Expression s.delete(owner) is a void method call, and thus it cannot be parameterized
    41Expression s.flush() is a void method call, and thus it cannot be parameterized
    42Expression assertFalse(s.contains(child)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    43Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    44Expression assertFalse(s.contains(child)) is a void method call, and thus it cannot be parameterized
    45Expression assertFalse(s.contains(child)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    46Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    47Expression assertFalse(s.contains(child)) is a void method call, and thus it cannot be parameterized