long initialInsertCount = sfi().getStatistics().getEntityInsertCount(); Session s = openSession(); MyEntity myEntity = new MyEntity( "test-persist"); myEntity.getNonInverseChildren().add( new MyChild( "test-child-persist-non-inverse" ) ); 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 MyChild" ).executeUpdate(); s.createQuery( "delete MyEntity" ).executeUpdate(); s.getTransaction().commit(); s.close();
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();
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 testPersistOutsideTransactionCascadedToNonInverseCollection() Method name: void testPersistOutsideTransactionCascadedToManyToOne()
Number of AST nodes: 16 Number of AST nodes: 16
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");
4
		myEntity.getNonInverseChildren().add( new MyChild( "test-child-persist-non-inverse" ) );
4
		myEntity.setSibling( new MySibling( "test-persist-sibling-out" ) );
5
		s.persist( myEntity );
5
		s.persist( myEntity );
6
		assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() );
6
		assertEquals( "persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount() );
7
		assertNull( myEntity.getId() );
7
		assertNull( myEntity.getId() );
8
		s.flush();
8
		s.flush();
9
		assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() );
9
		assertEquals( "delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount() );
10
		s.close();
10
		s.close();
11
		s = openSession();
11
		s = openSession();
12
		s.beginTransaction();
12
		s.beginTransaction();
13
		s.createQuery( "delete MyChild" ).executeUpdate();
13
		s.createQuery( "delete MyEntity" ).executeUpdate();
14
		s.createQuery( "delete MyEntity" ).executeUpdate();
14
		s.createQuery( "delete MySibling" ).executeUpdate();
15
		s.getTransaction().commit();
15
		s.getTransaction().commit();
16
		s.close();
16
		s.close();
Summary
Number of common nesting structure subtrees1
Number of refactorable cases1
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones locationClones are declared in the same class
Number of node comparisons175
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements15
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    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");
                                                                                                                                        
    4
    myEntity.setSibling(new MySibling("test-persist-sibling-out"));
    4
    myEntity.getNonInverseChildren().add(new MyChild("test-child-persist-non-inverse"));
                                                                                                                                                                                  
    5
    s.persist(myEntity);
    5
    s.persist(myEntity);
    6
    assertEquals("persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount());
    6
    assertEquals("persist on identity column not delayed", initialInsertCount, sfi().getStatistics().getEntityInsertCount());
    7
    assertNull(myEntity.getId());
    7
    assertNull(myEntity.getId());
    8
    s.flush();
    8
    s.flush();
    9
    assertEquals("delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount());
    9
    assertEquals("delayed persist insert not executed on flush", initialInsertCount + 2, sfi().getStatistics().getEntityInsertCount());
    10
    s.close();
    10
    s.close();
    11
    s = openSession();
    11
    s = openSession();
    12
    s.beginTransaction();
    12
    s.beginTransaction();
    13
    s.createQuery("delete MyChild").executeUpdate();
    13
    s.createQuery("delete MyChild").executeUpdate();
    14
    s.createQuery("delete MySibling").executeUpdate();
    Differences
    Expression1Expression2Difference
    "delete MyChild""delete MySibling"LITERAL_VALUE_MISMATCH
    14
    s.createQuery("delete MySibling").executeUpdate();
    14
    s.createQuery("delete MyEntity").executeUpdate();
    13
    s.createQuery("delete MyEntity").executeUpdate();
    15
    s.getTransaction().commit();
    15
    s.getTransaction().commit();
    16
    s.close();
    16
    s.close();
    Precondition Violations (0)
    Row Violation