Session s = openSession(); s.beginTransaction(); VersionedNode parent = new VersionedNode( "parent", "parent" ); s.persist( parent ); s.getTransaction().commit(); s.close(); clearCounts(); parent.setName( "new parent name" ); VersionedNode child = new VersionedNode( "child", "child"); parent.addChild( child ); s = openSession(); s.beginTransaction(); s.update( parent ); s.setReadOnly( parent, true ); s.getTransaction().commit(); s.close(); assertUpdateCount( 0 ); assertInsertCount( 1 ); s = openSession(); s.beginTransaction(); parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() ); child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() ); assertEquals( parent.getName(), "parent" ); assertEquals( 1, parent.getChildren().size() ); assertEquals( 0, parent.getVersion() ); assertSame( parent, child.getParent() ); assertSame( child, parent.getChildren().iterator().next() ); assertEquals( 0, child.getVersion() ); s.delete( parent ); s.delete( child ); s.getTransaction().commit(); s.close();
Session s = openSession(); s.beginTransaction(); VersionedNode child = new VersionedNode( "child", "child" ); s.persist( child ); s.getTransaction().commit(); s.close(); clearCounts(); child.setName( "new child name" ); VersionedNode parent = new VersionedNode( "parent", "parent"); parent.addChild( child ); s = openSession(); s.beginTransaction(); child = ( VersionedNode ) s.merge( child ); s.setReadOnly( child, true ); s.getTransaction().commit(); s.close(); assertUpdateCount( 1 ); assertInsertCount( 1 ); s = openSession(); s.beginTransaction(); parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() ); child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() ); assertEquals( child.getName(), "child" ); assertNull( child.getParent() ); assertEquals( 0, child.getVersion() ); assertNotNull( parent ); assertEquals( 0, parent.getChildren().size() ); assertEquals( 1, parent.getVersion() ); // hmmm, why is was version updated? s.delete( parent ); s.delete( child ); 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/readonly/ReadOnlyVersionedNodesTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyVersionedNodesTest.java
Method name: void testUpdateParentWithNewChildCommitWithReadOnlyParent() Method name: void testMergeDetachedChildWithNewParentCommitWithReadOnlyChild()
Number of AST nodes: 32 Number of AST nodes: 32
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		s.beginTransaction();
3
		VersionedNode parent = new VersionedNode( "parent", "parent" );
3
		VersionedNode child = new VersionedNode( "child", "child" );
4
		s.persist( parent );
4
		s.persist( child );
5
		s.getTransaction().commit();
5
		s.getTransaction().commit();
6
		s.close();
6
		s.close();
7
		clearCounts();
7
		clearCounts();
8
		parent.setName( "new parent name" );
8
		child.setName( "new child name" );
9
		VersionedNode child = new VersionedNode( "child", "child");
9
		VersionedNode parent = new VersionedNode( "parent", "parent");
10
		parent.addChild( child );
10
		parent.addChild( child );
11
		s = openSession();
11
		s = openSession();
12
		s.beginTransaction();
12
		s.beginTransaction();
13
		s.update( parent );
13
		child = ( VersionedNode ) s.merge( child );
14
		s.setReadOnly( parent, true );
14
		s.setReadOnly( child, true );
15
		s.getTransaction().commit();
15
		s.getTransaction().commit();
16
		s.close();
16
		s.close();
17
		assertUpdateCount( 0 );
17
		assertUpdateCount( 1 );
18
		assertInsertCount( 1 );
18
		assertInsertCount( 1 );
19
		s = openSession();
19
		s = openSession();
20
		s.beginTransaction();
20
		s.beginTransaction();
21
		parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() );
21
		parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() );
22
		child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() );
22
		child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() );
23
		assertEquals( parent.getName(), "parent" );
23
		assertEquals( child.getName(), "child" );
24
		assertEquals( 1, parent.getChildren().size() );
24
		assertNull( child.getParent() );
25
		assertEquals( 0, parent.getVersion() );
25
		assertEquals( 0, child.getVersion() );
26
		assertSame( parent, child.getParent() );
26
		assertNotNull( parent );
27
		assertSame( child, parent.getChildren().iterator().next() );
27
		assertEquals( 0, parent.getChildren().size() );
28
		assertEquals( 0, child.getVersion() );
28
		assertEquals( 1, parent.getVersion() );	// hmmm, why is was version updated?
29
		s.delete( parent );
29
		s.delete( parent );
30
		s.delete( child );
30
		s.delete( child );
31
		s.getTransaction().commit();
31
		s.getTransaction().commit();
32
		s.close();
32
		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 comparisons363
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements29
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
    2
    s.beginTransaction();
    2
    s.beginTransaction();
    3
    VersionedNode parent = new VersionedNode("parent", "parent");
    9
    VersionedNode parent = new VersionedNode("parent", "parent");
    4
    s.persist(parent);
    4
    s.persist(parent);
    4
    s.persist(child);
    Differences
    Expression1Expression2Difference
    parentchildVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4
    s.persist(child);
    5
    s.getTransaction().commit();
    5
    s.getTransaction().commit();
    6
    s.close();
    6
    s.close();
    7
    clearCounts();
    7
    clearCounts();
    8
    parent.setName("new parent name");
    8
    parent.setName("new parent name");
    8
    child.setName("new child name");
    Differences
    Expression1Expression2Difference
    "new parent name""new child name"LITERAL_VALUE_MISMATCH
    parentchildVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8
    child.setName("new child name");
    9
    VersionedNode child = new VersionedNode("child", "child");
    3
    VersionedNode child = new VersionedNode("child", "child");
    10
    parent.addChild(child);
    10
    parent.addChild(child);
    11
    s = openSession();
    11
    s = openSession();
    12
    s.beginTransaction();
    12
    s.beginTransaction();
    13
    s.update(parent);
    13
    s.update(parent);
    29
    s.delete(parent);
    Differences
    Expression1Expression2Difference
    updatedeleteMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression s.update(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.update(parent) is a void method call, and thus it cannot be parameterized
    Expression s.delete(parent) is a void method call, and thus it cannot be parameterized
    29
    s.delete(parent);
    14
    s.setReadOnly(parent, true);
    14
    s.setReadOnly(parent, true);
    30
    s.delete(child);
    Differences
    Expression1Expression2Difference
    setReadOnlydeleteMETHOD_INVOCATION_NAME_MISMATCH
    s.setReadOnly(parent,true)s.delete(child)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression s.setReadOnly(parent,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.setReadOnly(parent,true) is a void method call, and thus it cannot be parameterized
    Expression s.delete(child) is a void method call, and thus it cannot be parameterized
    Expression s.setReadOnly(parent,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.setReadOnly(parent,true) is a void method call, and thus it cannot be parameterized
    Expression s.delete(child) is a void method call, and thus it cannot be parameterized
    30
    s.delete(child);
    15
    s.getTransaction().commit();
    15
    s.getTransaction().commit();
    16
    s.close();
    16
    s.close();
    17
    assertUpdateCount(0);
    17
    assertUpdateCount(0);
    17
    assertUpdateCount(1);
    Differences
    Expression1Expression2Difference
    01LITERAL_VALUE_MISMATCH
    17
    assertUpdateCount(1);
    18
    assertInsertCount(1);
    18
    assertInsertCount(1);
    19
    s = openSession();
    19
    s = openSession();
    20
    s.beginTransaction();
    20
    s.beginTransaction();
    21
    parent = (VersionedNode)s.get(VersionedNode.class, parent.getId());
    21
    parent = (VersionedNode)s.get(VersionedNode.class, parent.getId());
    13
    child = (VersionedNode)s.merge(child);
    Differences
    Expression1Expression2Difference
    parentchildVARIABLE_NAME_MISMATCH
    getmergeMETHOD_INVOCATION_NAME_MISMATCH
    s.get(VersionedNode.class,parent.getId())s.merge(child)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.get(VersionedNode.class,parent.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.merge(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.get(VersionedNode.class,parent.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.merge(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13
    child = (VersionedNode)s.merge(child);
    22
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
    22
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
    21
    parent = (VersionedNode)s.get(VersionedNode.class, parent.getId());
    Differences
    Expression1Expression2Difference
    childparentVARIABLE_NAME_MISMATCH
    childparentVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21
    parent = (VersionedNode)s.get(VersionedNode.class, parent.getId());
                                                                                                                                        
    22
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
    Preondition Violations
    Unmatched statement child=(VersionedNode)s.get(VersionedNode.class,child.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    22
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
    23
    assertEquals(parent.getName(), "parent");
    23
    assertEquals(parent.getName(), "parent");
    23
    assertEquals(child.getName(), "child");
    Differences
    Expression1Expression2Difference
    parentchildVARIABLE_NAME_MISMATCH
    "parent""child"LITERAL_VALUE_MISMATCH
    Preondition Violations
    Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23
    assertEquals(child.getName(), "child");
    24
    assertEquals(1, parent.getChildren().size());
    24
    assertEquals(1, parent.getChildren().size());
    Preondition Violations
    Unmatched statement assertEquals(1,parent.getChildren().size()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                    
    25
    assertEquals(0, parent.getVersion());
    25
    assertEquals(0, parent.getVersion());
    Preondition Violations
    Unmatched statement assertEquals(0,parent.getVersion()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                    
    26
    assertSame(parent, child.getParent());
    26
    assertSame(parent, child.getParent());
    24
    assertNull(child.getParent());
    Differences
    Expression1Expression2Difference
    assertSameassertNullMETHOD_INVOCATION_NAME_MISMATCH
    assertSame(parent,child.getParent())assertNull(child.getParent())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertSame(parent,child.getParent()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(child.getParent()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertSame(parent,child.getParent()) is a void method call, and thus it cannot be parameterized
    Expression assertNull(child.getParent()) is a void method call, and thus it cannot be parameterized
    Expression assertSame(parent,child.getParent()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(child.getParent()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertSame(parent,child.getParent()) is a void method call, and thus it cannot be parameterized
    Expression assertNull(child.getParent()) is a void method call, and thus it cannot be parameterized
    24
    assertNull(child.getParent());
                                                                                  
    25
    assertEquals(0, child.getVersion());
    27
    assertSame(child, parent.getChildren().iterator().next());
    27
    assertSame(child, parent.getChildren().iterator().next());
    26
    assertNotNull(parent);
    Differences
    Expression1Expression2Difference
    assertSameassertNotNullMETHOD_INVOCATION_NAME_MISMATCH
    assertSame(child,parent.getChildren().iterator().next())assertNotNull(parent)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertSame(child,parent.getChildren().iterator().next()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNotNull(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertSame(child,parent.getChildren().iterator().next()) is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(parent) is a void method call, and thus it cannot be parameterized
    Expression assertSame(child,parent.getChildren().iterator().next()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNotNull(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertSame(child,parent.getChildren().iterator().next()) is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(parent) is a void method call, and thus it cannot be parameterized
    26
    assertNotNull(parent);
                                                                                                    
    27
    assertEquals(0, parent.getChildren().size());
    Preondition Violations
    Unmatched statement assertEquals(0,parent.getChildren().size()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    27
    assertEquals(0, parent.getChildren().size());
    28
    assertEquals(0, child.getVersion());
    28
    assertEquals(0, child.getVersion());
    28
    assertEquals(1, parent.getVersion());
    Differences
    Expression1Expression2Difference
    01LITERAL_VALUE_MISMATCH
    childparentVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    28
    assertEquals(1, parent.getVersion());
    29
    s.delete(parent);
    29
    s.delete(parent);
    14
    s.setReadOnly(child, true);
    Differences
    Expression1Expression2Difference
    deletesetReadOnlyMETHOD_INVOCATION_NAME_MISMATCH
    s.delete(parent)s.setReadOnly(child,true)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression s.delete(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.setReadOnly(child,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(parent) is a void method call, and thus it cannot be parameterized
    Expression s.setReadOnly(child,true) is a void method call, and thus it cannot be parameterized
    Expression s.delete(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.setReadOnly(child,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(parent) is a void method call, and thus it cannot be parameterized
    Expression s.setReadOnly(child,true) is a void method call, and thus it cannot be parameterized
    14
    s.setReadOnly(child, true);
    30
    s.delete(child);
    30
    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
                                            
    31
    s.getTransaction().commit();
    31
    s.getTransaction().commit();
    32
    s.close();
    32
    s.close();
    Precondition Violations (60)
    Row Violation
    1Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Expression s.update(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression s.delete(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression s.update(parent) is a void method call, and thus it cannot be parameterized
    8Expression s.delete(parent) is a void method call, and thus it cannot be parameterized
    9Expression s.setReadOnly(parent,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression s.delete(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression s.setReadOnly(parent,true) is a void method call, and thus it cannot be parameterized
    12Expression s.delete(child) is a void method call, and thus it cannot be parameterized
    13Expression s.setReadOnly(parent,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression s.delete(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression s.setReadOnly(parent,true) is a void method call, and thus it cannot be parameterized
    16Expression s.delete(child) is a void method call, and thus it cannot be parameterized
    17Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19Expression s.get(VersionedNode.class,parent.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    20Expression s.merge(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21Expression s.get(VersionedNode.class,parent.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression s.merge(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    24Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    26Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    27Unmatched statement child=(VersionedNode)s.get(VersionedNode.class,child.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    28Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    29Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    30Unmatched statement assertEquals(1,parent.getChildren().size()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    31Unmatched statement assertEquals(0,parent.getVersion()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    32Expression assertSame(parent,child.getParent()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    33Expression assertNull(child.getParent()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    34Expression assertSame(parent,child.getParent()) is a void method call, and thus it cannot be parameterized
    35Expression assertNull(child.getParent()) is a void method call, and thus it cannot be parameterized
    36Expression assertSame(parent,child.getParent()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    37Expression assertNull(child.getParent()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    38Expression assertSame(parent,child.getParent()) is a void method call, and thus it cannot be parameterized
    39Expression assertNull(child.getParent()) is a void method call, and thus it cannot be parameterized
    40Expression assertSame(child,parent.getChildren().iterator().next()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    41Expression assertNotNull(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    42Expression assertSame(child,parent.getChildren().iterator().next()) is a void method call, and thus it cannot be parameterized
    43Expression assertNotNull(parent) is a void method call, and thus it cannot be parameterized
    44Expression assertSame(child,parent.getChildren().iterator().next()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    45Expression assertNotNull(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    46Expression assertSame(child,parent.getChildren().iterator().next()) is a void method call, and thus it cannot be parameterized
    47Expression assertNotNull(parent) is a void method call, and thus it cannot be parameterized
    48Unmatched statement assertEquals(0,parent.getChildren().size()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    49Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    50Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    51Expression s.delete(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    52Expression s.setReadOnly(child,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    53Expression s.delete(parent) is a void method call, and thus it cannot be parameterized
    54Expression s.setReadOnly(child,true) is a void method call, and thus it cannot be parameterized
    55Expression s.delete(parent) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    56Expression s.setReadOnly(child,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    57Expression s.delete(parent) is a void method call, and thus it cannot be parameterized
    58Expression s.setReadOnly(child,true) is a void method call, and thus it cannot be parameterized
    59Unmatched statement s.delete(child); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    60Clone fragment #1 returns variables , while Clone fragment #2 returns variables child, s