Session s = openSession(); s.beginTransaction(); Customer cust = new Customer( "Acme, Inc." ); Order order = new Order( new Order.Id( cust, 1 ) ); cust.getOrders().add( order ); s.save( cust ); s.flush(); assertEquals( 2, sfi().getStatistics().getEntityInsertCount() ); s.delete( cust ); s.getTransaction().commit(); s.close();
Session s = openSession(); Transaction t = s.beginTransaction(); Speech speech = new Speech(); speech.setLength( new Double( 23d ) ); speech.setName( "Mine" ); s.persist( speech ); s.flush(); s.clear(); List l = s.createSQLQuery( "select name, id, flength, name as scalarName from Speech" ) .setResultSetMapping( "speech" ) .list(); assertEquals( l.size(), 1 ); t.rollback(); 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/keymanytoone/bidir/component/EagerKeyManyToOneTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
Method name: void testSaveCascadedToKeyManyToOne() Method name: void testMixAndMatchEntityScalar()
Number of AST nodes: 11 Number of AST nodes: 12
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		Transaction t = s.beginTransaction();
3
		Customer cust = new Customer( "Acme, Inc." );
3
		Speech speech = new Speech();
4
		Order order = new Order( new Order.Id( cust, 1 ) );
4
		speech.setLength( new Double( 23d ) );
5
		cust.getOrders().add( order );
5
		speech.setName( "Mine" );
6
		s.save( cust );
6
		s.persist( speech );
7
		s.flush();
7
		s.flush();
8
		assertEquals( 2, sfi().getStatistics().getEntityInsertCount() );
8
		
9
		s.delete( cu
9
s.clear();
10
		List l = s.createSQLQuery( "select name, id, flength, name as scalarName from Speech" )
11
				.setResultSetMapping( "speech" )
10
st );
12
				.list();
11
		s.getTransaction().commit
13
		assertEquals( l.size(), 1 );
12
();
14
		t.rollback();
13
		s.close();
15
		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 comparisons132
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements6
    Number of unmapped statements in the first code fragment5
    Number of unmapped statements in the second code fragment6
    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 t = s.beginTransaction();
    Preondition Violations
    Unmatched statement Transaction t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2
    Transaction t = s.beginTransaction();
    2
    s.beginTransaction();
                                                    
                                                                
    3
    Speech speech = new Speech();
    3
    Customer cust = new Customer("Acme, Inc.");
                                                                                            
                                                                              
    4
    speech.setLength(new Double(23d));
    4
    Order order = new Order(new Order.Id(cust, 1));
                                                                                                  
                                                        
    5
    speech.setName("Mine");
    5
    cust.getOrders().add(order);
                                                                  
    6
    s.save(cust);
                                    
    7
    s.flush();
    7
    s.flush();
    8
    assertEquals(2, sfi().getStatistics().getEntityInsertCount());
    8
    assertEquals(2, sfi().getStatistics().getEntityInsertCount());
    6
    s.persist(speech);
    Differences
    Expression1Expression2Difference
    assertEqualspersistMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(2,sfi().getStatistics().getEntityInsertCount())s.persist(speech)ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.persist(speech) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(2,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    Expression s.persist(speech) is a void method call, and thus it cannot be parameterized
    Expression s.persist(speech) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(2,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    Expression s.persist(speech) is a void method call, and thus it cannot be parameterized
    6
    s.persist(speech);
    9
    s.delete(cust);
    9
    s.delete(cust);
    8
    s.clear();
    Differences
    Expression1Expression2Difference
    deleteclearMETHOD_INVOCATION_NAME_MISMATCH
    s.delete(cust)s.clear()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression s.delete(cust) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.clear() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(cust) is a void method call, and thus it cannot be parameterized
    Expression s.clear() is a void method call, and thus it cannot be parameterized
    Expression s.delete(cust) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.clear() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(cust) is a void method call, and thus it cannot be parameterized
    Expression s.clear() is a void method call, and thus it cannot be parameterized
    8
    s.clear();
                                                                                                                                                                                                                                                            
    9
    List l = s.createSQLQuery("select name, id, flength, name as scalarName from Speech").setResultSetMapping("speech").list();
                                                              
    10
    assertEquals(l.size(), 1);
    10
    s.getTransaction().commit();
    10
    s.getTransaction().commit();
    11
    t.rollback();
    Differences
    Expression1Expression2Difference
    commitrollbackMETHOD_INVOCATION_NAME_MISMATCH
    s.getTransaction()tTYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression s.getTransaction().commit() 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 t.rollback() is a void method call, and thus it cannot be parameterized
    Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11
    t.rollback();
    11
    s.close();
    12
    s.close();
    Precondition Violations (19)
    Row Violation
    1Unmatched statement Transaction t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Expression s.persist(speech) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression assertEquals(2,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    4Expression s.persist(speech) is a void method call, and thus it cannot be parameterized
    5Expression s.persist(speech) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression assertEquals(2,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    7Expression s.persist(speech) is a void method call, and thus it cannot be parameterized
    8Expression s.delete(cust) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression s.clear() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression s.delete(cust) is a void method call, and thus it cannot be parameterized
    11Expression s.clear() is a void method call, and thus it cannot be parameterized
    12Expression s.delete(cust) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression s.clear() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression s.delete(cust) is a void method call, and thus it cannot be parameterized
    15Expression s.clear() is a void method call, and thus it cannot be parameterized
    16Expression s.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    18Expression t.rollback() is a void method call, and thus it cannot be parameterized
    19Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted