long initialInsertCount = sfi().getStatistics().getEntityInsertCount(); Session s = openSession(); MyEntity myEntity = new MyEntity( "test-persist"); myEntity.setSibling( new MySibling( "test-persist-sibling-out" ) ); s.persist( myEntity ); assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() ); assertNull( myEntity.getId() ); s.flush(); assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() ); s.close(); s = openSession(); s.beginTransaction(); s.createQuery( "delete MyEntity" ).executeUpdate(); s.createQuery( "delete MySibling" ).executeUpdate(); s.getTransaction().commit(); s.close();
long initialInsertCount = sfi().getStatistics().getEntityInsertCount(); Session s = openSession(); MyEntity myEntity2 = new MyEntity( "test-persist-2"); MySibling sibling = new MySibling( "test-persist-sibling-in" ); sibling.setEntity( myEntity2 ); s.persist( sibling ); assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() ); assertNull( myEntity2.getId() ); s.flush(); assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() ); s.close(); s = openSession(); s.beginTransaction(); s.createQuery( "delete MySibling" ).executeUpdate(); s.createQuery( "delete MyEntity" ).executeUpdate(); s.getTransaction().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/generatedkeys/identity/IdentityGeneratedKeysTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/generatedkeys/identity/IdentityGeneratedKeysTest.java
Method name: void testPersistOutsideTransactionCascadedToManyToOne() Method name: void testPersistOutsideTransactionCascadedFromManyToOne()
Number of AST nodes: 16 Number of AST nodes: 17
1
long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
1
long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
2
		Session s = openSession();
2
		Session s = openSession();
3
		MyEntity myEntity = new MyEntity( "test-persist");
3
		MyEntity myEntity2 = new MyEntity( "test-persist-2");
4
		myEntity.setSibling( new MySibling( "test-persist-sibling-out" ) );
4
		MySibling sibling = new MySibling( "test-persist-sibling-in" );
5
		s.persist( myEntity
5
		sibling.setEntity( myEntity2 );
6
 );
6
		s.persist( sibling );
7
		assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() );
7
		assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() );
8
		assertNull( myEntity.getId() );
8
		assertNull( myEntity2.getId() );
9
		s.flush();
9
		s.flush();
10
		assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() );
10
		assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() );
11
		s.close();
11
		s.close();
12
		s = openSession();
12
		s = openSession();
13
		s.beginTransaction();
13
		s.beginTransaction();
14
		s.createQuery( "delete MyEntity" ).executeUpdate();
14
		s.createQuery( "delete MySibling" ).executeUpdate();
15
		s.createQuery( "delete MySibling" ).executeUpdate();
15
		s.createQuery( "delete MyEntity" ).executeUpdate();
16
		s.getTransaction().commit();
16
		s.getTransaction().commit();
17
		s.close();
17
		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 declared in the same class
Number of node comparisons190
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements15
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
    1
    long initialInsertCount = sfi().getStatistics().getEntityInsertCount();
    2
    Session s = openSession();
    2
    Session s = openSession();
    3
    MyEntity myEntity = new MyEntity("test-persist");
    3
    MyEntity myEntity = new MyEntity("test-persist");
    3
    MyEntity myEntity2 = new MyEntity("test-persist-2");
    Differences
    Expression1Expression2Difference
    myEntitymyEntity2VARIABLE_NAME_MISMATCH
    "test-persist""test-persist-2"LITERAL_VALUE_MISMATCH
    3
    MyEntity myEntity2 = new MyEntity("test-persist-2");
                                                                                                                                
    4
    MySibling sibling = new MySibling("test-persist-sibling-in");
                                                                    
    5
    sibling.setEntity(myEntity2);
    4
    myEntity.setSibling(new MySibling("test-persist-sibling-out"));
    4
    myEntity.setSibling(new MySibling("test-persist-sibling-out"));
    7
    assertEquals("persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount());
    Differences
    Expression1Expression2Difference
    setSiblingassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    myEntity.setSibling(new MySibling("test-persist-sibling-out"))assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount())ARGUMENT_NUMBER_MISMATCH
    myEntityMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression myEntity.setSibling(new MySibling("test-persist-sibling-out")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression myEntity.setSibling(new MySibling("test-persist-sibling-out")) is a void method call, and thus it cannot be parameterized
    Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    Expression myEntity.setSibling(new MySibling("test-persist-sibling-out")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression myEntity.setSibling(new MySibling("test-persist-sibling-out")) is a void method call, and thus it cannot be parameterized
    Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    7
    assertEquals("persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount());
    5
    s.persist(myEntity);
    5
    s.persist(myEntity);
    6
    s.persist(sibling);
    Differences
    Expression1Expression2Difference
    myEntitysiblingVARIABLE_NAME_MISMATCH
    org.hibernate.test.generatedkeys.identity.MyEntityorg.hibernate.test.generatedkeys.identity.MySiblingVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Expression myEntity cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Type org.hibernate.test.generatedkeys.identity.MyEntity of variable myEntity does not match with type org.hibernate.test.generatedkeys.identity.MySibling of variable sibling
    • Make classes org.hibernate.test.generatedkeys.identity.MyEntity and org.hibernate.test.generatedkeys.identity.MySibling extend a common superclass
    6
    s.persist(sibling);
    6
    assertEquals("persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount());
    6
    assertEquals("persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount());
    8
    assertNull(myEntity2.getId());
    Differences
    Expression1Expression2Difference
    assertEqualsassertNullMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount())assertNull(myEntity2.getId())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(myEntity2.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    Expression assertNull(myEntity2.getId()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(myEntity2.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    Expression assertNull(myEntity2.getId()) is a void method call, and thus it cannot be parameterized
    8
    assertNull(myEntity2.getId());
    7
    assertNull(myEntity.getId());
    7
    assertNull(myEntity.getId());
    16
    s.getTransaction().commit();
    Differences
    Expression1Expression2Difference
    assertNullcommitMETHOD_INVOCATION_NAME_MISMATCH
    assertNull(myEntity.getId())s.getTransaction().commit()ARGUMENT_NUMBER_MISMATCH
    s.getTransaction()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertNull(myEntity.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(myEntity.getId()) is a void method call, and thus it cannot be parameterized
    Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    Expression assertNull(myEntity.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(myEntity.getId()) is a void method call, and thus it cannot be parameterized
    Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    16
    s.getTransaction().commit();
    8
    s.flush();
    9
    s.flush();
    9
    assertEquals("delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount());
    10
    assertEquals("delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount());
    10
    s.close();
    11
    s.close();
    11
    s = openSession();
    12
    s = openSession();
    12
    s.beginTransaction();
    13
    s.beginTransaction();
    13
    s.createQuery("delete MyEntity").executeUpdate();
    15
    s.createQuery("delete MyEntity").executeUpdate();
    14
    s.createQuery("delete MySibling").executeUpdate();
    14
    s.createQuery("delete MySibling").executeUpdate();
    15
    s.getTransaction().commit();
                                                                    
    16
    s.close();
    17
    s.close();
    Precondition Violations (27)
    Row Violation
    1Expression myEntity.setSibling(new MySibling("test-persist-sibling-out")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression myEntity.setSibling(new MySibling("test-persist-sibling-out")) is a void method call, and thus it cannot be parameterized
    4Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    5Expression myEntity.setSibling(new MySibling("test-persist-sibling-out")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression myEntity.setSibling(new MySibling("test-persist-sibling-out")) is a void method call, and thus it cannot be parameterized
    8Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    9Expression myEntity cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Type org.hibernate.test.generatedkeys.identity.MyEntity of variable myEntity does not match with type org.hibernate.test.generatedkeys.identity.MySibling of variable sibling
    11Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression assertNull(myEntity2.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    14Expression assertNull(myEntity2.getId()) is a void method call, and thus it cannot be parameterized
    15Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Expression assertNull(myEntity2.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression assertEquals("persist on identity column not delayed",initialInsertCount,sfi().getStatistics().getEntityInsertCount()) is a void method call, and thus it cannot be parameterized
    18Expression assertNull(myEntity2.getId()) is a void method call, and thus it cannot be parameterized
    19Expression assertNull(myEntity.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    20Expression s.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21Expression assertNull(myEntity.getId()) is a void method call, and thus it cannot be parameterized
    22Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    23Expression assertNull(myEntity.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    24Expression s.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Expression assertNull(myEntity.getId()) is a void method call, and thus it cannot be parameterized
    26Expression s.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    27Clone fragment #1 returns variable s with type org.hibernate.Session , while Clone fragment #2 returns variable myEntity2 with type org.hibernate.test.generatedkeys.identity.MyEntity