Session s = openSession(); s.beginTransaction(); VersionedNode parent = new VersionedNode( "parent", "parent" ); s.persist( parent ); s.getTransaction().commit(); s.close(); clearCounts(); s = openSession(); s.beginTransaction(); VersionedNode parentManaged = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() ); s.setReadOnly( parentManaged, true ); parentManaged.setName( "new parent name" ); VersionedNode child = new VersionedNode( "child", "child"); parentManaged.addChild( child ); s.getTransaction().commit(); s.close(); assertUpdateCount( 0 ); assertInsertCount( 0 ); s = openSession(); s.beginTransaction(); parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() ); assertEquals( "parent", parent.getName() ); assertEquals( 0, parent.getChildren().size() ); assertEquals( 0, parent.getVersion() ); child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() ); assertNull( child ); s.delete( parent ); 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(); s = openSession(); s.beginTransaction(); VersionedNode childManaged = ( VersionedNode ) s.get( VersionedNode.class, child.getId() ); s.setReadOnly( childManaged, true ); childManaged.setName( "new child name" ); VersionedNode parent = new VersionedNode( "parent", "parent"); parent.addChild( childManaged ); s.getTransaction().commit(); s.close(); assertUpdateCount( 0 ); assertInsertCount( 0 ); s = openSession(); s.beginTransaction(); child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() ); assertEquals( "child", child.getName() ); assertNull( child.getParent() ); assertEquals( 0, child.getVersion() ); parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() ); assertNull( 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 testAddNewChildToReadOnlyParent() Method name: void testAddNewParentToReadOnlyChild()
Number of AST nodes: 29 Number of AST nodes: 29
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
		s = openSession();
8
		s = openSession();
9
		s.beginTransaction();
9
		s.beginTransaction();
10
		VersionedNode parentManaged = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() );
10
		VersionedNode childManaged = ( VersionedNode ) s.get( VersionedNode.class, child.getId() );
11
		s.setReadOnly( parentManaged, true );
11
		s.setReadOnly( childManaged, true );
12
		parentManaged.setName( "new parent name" );
12
		childManaged.setName( "new child name" );
13
		VersionedNode child = new VersionedNode( "child", "child");
13
		VersionedNode parent = new VersionedNode( "parent", "parent");
14
		parentManaged.addChild( child );
14
		parent.addChild( childManaged );
15
		s.getTransaction().commit();
15
		s.getTransaction().commit();
16
		s.close();
16
		s.close();
17
		assertUpdateCount( 0 );
17
		assertUpdateCount( 0 );
18
		assertInsertCount( 0 );
18
		assertInsertCount( 0 );
19
		s = openSession();
19
		s = openSession();
20
		s.beginTransaction();
20
		s.beginTransaction();
21
		parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() );
21
		child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() );
22
		assertEquals( "parent", parent.getName() );
22
		assertEquals( "child", child.getName() );
23
		assertEquals( 0, parent.getChildren().size() );
23
		assertNull( child.getParent() );
24
		assertEquals( 0, parent.getVersion() );
24
		assertEquals( 0, child.getVersion() );
25
		child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() );
25
		parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() );
26
		assertNull( child );
26
		assertNull( parent );
27
		s.delete( parent );
27
		s.delete( child );
28
		s.getTransaction().commit();
28
		s.getTransaction().commit();
29
		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 declared in the same class
Number of node comparisons237
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements29
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    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");
    13
    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
    s = openSession();
    8
    s = openSession();
    9
    s.beginTransaction();
    9
    s.beginTransaction();
    10
    VersionedNode parentManaged = (VersionedNode)s.get(VersionedNode.class, parent.getId());
    10
    VersionedNode parentManaged = (VersionedNode)s.get(VersionedNode.class, parent.getId());
    10
    VersionedNode childManaged = (VersionedNode)s.get(VersionedNode.class, child.getId());
    Differences
    Expression1Expression2Difference
    parentManagedchildManagedVARIABLE_NAME_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
    10
    VersionedNode childManaged = (VersionedNode)s.get(VersionedNode.class, child.getId());
    11
    s.setReadOnly(parentManaged, true);
    11
    s.setReadOnly(parentManaged, true);
    11
    s.setReadOnly(childManaged, true);
    Differences
    Expression1Expression2Difference
    parentManagedchildManagedVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression parentManaged cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression childManaged cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11
    s.setReadOnly(childManaged, true);
    12
    parentManaged.setName("new parent name");
    12
    parentManaged.setName("new parent name");
    12
    childManaged.setName("new child name");
    Differences
    Expression1Expression2Difference
    "new parent name""new child name"LITERAL_VALUE_MISMATCH
    parentManagedchildManagedVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression parentManaged cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression childManaged cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12
    childManaged.setName("new child name");
    13
    VersionedNode child = new VersionedNode("child", "child");
    3
    VersionedNode child = new VersionedNode("child", "child");
    14
    parentManaged.addChild(child);
    14
    parentManaged.addChild(child);
    14
    parent.addChild(childManaged);
    Differences
    Expression1Expression2Difference
    childchildManagedVARIABLE_NAME_MISMATCH
    parentManagedparentVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression childManaged cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression parentManaged 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
    14
    parent.addChild(childManaged);
    15
    s.getTransaction().commit();
    15
    s.getTransaction().commit();
    16
    s.close();
    16
    s.close();
    17
    assertUpdateCount(0);
    17
    assertUpdateCount(0);
    18
    assertInsertCount(0);
    18
    assertInsertCount(0);
    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());
    21
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
    Differences
    Expression1Expression2Difference
    parentchildVARIABLE_NAME_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
    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
    21
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
    22
    assertEquals("parent", parent.getName());
    22
    assertEquals("parent", parent.getName());
    22
    assertEquals("child", child.getName());
    Differences
    Expression1Expression2Difference
    "parent""child"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
    22
    assertEquals("child", child.getName());
    23
    assertEquals(0, parent.getChildren().size());
    23
    assertEquals(0, parent.getChildren().size());
    23
    assertNull(child.getParent());
    Differences
    Expression1Expression2Difference
    assertEqualsassertNullMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(0,parent.getChildren().size())assertNull(child.getParent())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(0,parent.getChildren().size()) 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 assertEquals(0,parent.getChildren().size()) 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 assertEquals(0,parent.getChildren().size()) 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 assertEquals(0,parent.getChildren().size()) 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
    23
    assertNull(child.getParent());
    24
    assertEquals(0, parent.getVersion());
    24
    assertEquals(0, parent.getVersion());
    24
    assertEquals(0, child.getVersion());
    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
    24
    assertEquals(0, child.getVersion());
    25
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
    25
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
    25
    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
    25
    parent = (VersionedNode)s.get(VersionedNode.class, parent.getId());
    26
    assertNull(child);
    26
    assertNull(child);
    26
    assertNull(parent);
    Differences
    Expression1Expression2Difference
    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
    26
    assertNull(parent);
    27
    s.delete(parent);
    27
    s.delete(parent);
    27
    s.delete(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
    27
    s.delete(child);
    28
    s.getTransaction().commit();
    28
    s.getTransaction().commit();
    29
    s.close();
    29
    s.close();
    Precondition Violations (36)
    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 parentManaged cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression childManaged cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression parentManaged cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression childManaged cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression childManaged cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression parentManaged cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    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 assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    20Expression assertNull(child.getParent()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    22Expression assertNull(child.getParent()) is a void method call, and thus it cannot be parameterized
    23Expression assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    24Expression assertNull(child.getParent()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    26Expression assertNull(child.getParent()) is a void method call, and thus it cannot be parameterized
    27Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    28Expression child 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
    30Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    31Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    32Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    33Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    34Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    35Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    36Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted