if ( getDialect().doesReadCommittedCauseWritersToBlockReaders()) { reportSkip( "lock blocking", "stale versioned instance" ); return; } String check = "EJB3 Specification"; Session s1 = getSessions().openSession(); Transaction t1 = s1.beginTransaction(); Item item = new Item( check ); s1.save( item ); t1.commit(); s1.close(); Long itemId = item.getId(); long initialVersion = item.getVersion(); // Now, open a new Session and re-load the item... s1 = getSessions().openSession(); t1 = s1.beginTransaction(); item = ( Item ) s1.get( Item.class, itemId ); // now that the item is associated with the persistence-context of that session, // open a new session and modify it "behind the back" of the first session Session s2 = getSessions().openSession(); Transaction t2 = s2.beginTransaction(); Item item2 = ( Item ) s2.get( Item.class, itemId ); item2.setName( "EJB3 Persistence Spec" ); t2.commit(); s2.close(); // at this point, s1 now contains stale data, so try an hql query which // returns said item and make sure we get the previously associated state // (i.e., the old name and the old version) item2 = ( Item ) s1.createQuery( "select i from Item i" ).list().get( 0 ); assertTrue( item == item2 ); assertEquals( "encountered non-repeatable read", check, item2.getName() ); assertEquals( "encountered non-repeatable read", initialVersion, item2.getVersion() ); t1.commit(); s1.close(); // clean up s1 = getSessions().openSession(); t1 = s1.beginTransaction(); s1.createQuery( "delete Item" ).executeUpdate(); t1.commit(); s1.close();
if ( getDialect().doesReadCommittedCauseWritersToBlockReaders()) { reportSkip( "lock blocking", "stale versioned instance" ); return; } String check = "Lock Modes"; Session s1 = getSessions().openSession(); Transaction t1 = s1.beginTransaction(); Part part = new Part( new Item( "EJB3 Specification" ), check, "3.3.5.3", new BigDecimal( 0.0 ) ); s1.save( part ); t1.commit(); s1.close(); Long partId = part.getId(); // Now, open a new Session and re-load the part... s1 = getSessions().openSession(); t1 = s1.beginTransaction(); part = ( Part ) s1.get( Part.class, partId ); // now that the item is associated with the persistence-context of that session, // open a new session and modify it "behind the back" of the first session Session s2 = getSessions().openSession(); Transaction t2 = s2.beginTransaction(); Part part2 = ( Part ) s2.get( Part.class, partId ); part2.setName( "Lock Mode Types" ); t2.commit(); s2.close(); // at this point, s1 now contains stale data, so try an hql query which // returns said part and make sure we get the previously associated state // (i.e., the old name) part2 = ( Part ) s1.createQuery( "select p from Part p" ).list().get( 0 ); assertTrue( part == part2 ); assertEquals( "encountered non-repeatable read", check, part2.getName() ); t1.commit(); s1.close(); // clean up s1 = getSessions().openSession(); t1 = s1.beginTransaction(); s1.delete( part2 ); s1.delete( part2.getItem() ); t1.commit(); s1.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/jpa/lock/RepeatableReadTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/jpa/lock/RepeatableReadTest.java
Method name: void testStaleVersionedInstanceFoundInQueryResult() Method name: void testStaleNonVersionedInstanceFoundInQueryResult()
Number of AST nodes: 32 Number of AST nodes: 31
1
if ( getDialect().doesReadCommittedCauseWritersToBlockReaders()) {
1
if ( getDialect().doesReadCommittedCauseWritersToBlockReaders()) {
2
			reportSkip( "lock blocking", "stale versioned instance" );
2
			reportSkip( "lock blocking", "stale versioned instance" );
3
			return;
3
			return;
4
		}
4
		}
5
		String check = "EJB3 Specification";
5
		String check = "Lock Modes";
6
		Session s1 = getSessions().openSession();
6
		Session s1 = getSessions().openSession();
7
		Transaction t1 = s1.beginTransaction();
7
		Transaction t1 = s1.beginTransaction();
8
		Item item = new Item( check );
8
		Part part = new Part( new Item( "EJB3 Specification" ), check, "3.3.5.3", new BigDecimal( 0.0 ) );
9
		s1.save(  item );
9
		s1.save( part );
10
		t1.commit();
10
		t1.commit();
11
		s1.close();
11
		s1.close();
12
		Long itemId = item.getId();
12
		Long partId = 
13
		long initialVersion = item.getVersion();
13
part.getId();
14
		// Now, open a new Session and re-load the item...
14
		// Now, open a new Session and re-load the part...
15
		s1 = getSessions().openSession();
15
		s1 = getSessions().openSession();
16
		t1 = s1.beginTransaction();
16
		t1 = s1.beginTransaction();
17
		item = ( Item ) s1.get( Item.class, itemId );
17
		part = ( Part ) s1.get( Part.class, partId );
18
		// now that the item is associated with the persistence-context of that session,
18
		// now that the item is associated with the persistence-context of that session,
19
		// open a new session and modify it "behind the back" of the first session
19
		// open a new session and modify it "behind the back" of the first session
20
		Session s2 = getSessions().openSession();
20
		Session s2 = getSessions().openSession();
21
		Transaction t2 = s2.beginTransaction();
21
		Transaction t2 = s2.beginTransaction();
22
		Item item2 = ( Item ) s2.get( Item.class, itemId );
22
		Part part2 = ( Part ) s2.get( Part.class, partId );
23
		item2.setName( "EJB3 Persistence Spec" );
23
		part2.setName( "Lock Mode Types" );
24
		t2.commit();
24
		t2.commit();
25
		s2.close();
25
		s2.close();
26
		// at this point, s1 now contains stale data, so try an hql query which
26
		// at this point, s1 now contains stale data, so try an hql query which
27
		// returns said item and make sure we get the previously associated state
27
		// returns said part and make sure we get the previously associated state
28
		// (i.e., the old name and the old version)
28
		// (i.e., the old name)
29
		item2 = ( Item ) s1.createQuery( "select i from Item i" ).list().get( 0 );
29
		part2 = ( Part ) s1.createQuery( "select p from Part p" ).list().get( 0 );
30
		assertTrue( item == item2 );
30
		assertTrue( part == part2 );
31
		assertEquals( "encountered non-repeatable read", check, item2.getName() );
31
		assertEquals( "encountered non-repeatable read", check, 
32
		assertEquals( "encountered non-repeatable read", initialVersion, item2.getVersion() );
32
part2.getName() );
33
		t1.commit();
33
		t1.commit();
34
		s1.close();
34
		s1.close();
35
		// clean up
35
		// clean up
36
		s1 = getSessions().openSession();
36
		s1 = getSessions().openSession();
37
		t1 = s1.beginTransaction();
37
		t1 = s1.beginTransaction();
38
		s1.createQuery( "delete Item" ).executeUpdate(
38
		s1.delete( part2 );
39
);
39
		s1.delete( part2.getItem() );
40
		t1.commit();
40
		t1.commit();
41
		s1.close();
41
		s1.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.1
Clones locationClones are declared in the same class
Number of node comparisons312
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements24
    Number of unmapped statements in the first code fragment8
    Number of unmapped statements in the second code fragment7
    Time elapsed for statement mapping (ms)11.3
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    if (getDialect().doesReadCommittedCauseWritersToBlockReaders())
    1
    if (getDialect().doesReadCommittedCauseWritersToBlockReaders())
    2
    reportSkip("lock blocking", "stale versioned instance");
    2
    reportSkip("lock blocking", "stale versioned instance");
    3
    return;
    3
    return;
    4
    String check = "EJB3 Specification";
    4
    String check = "EJB3 Specification";
    4
    String check = "Lock Modes";
    Differences
    Expression1Expression2Difference
    "EJB3 Specification""Lock Modes"LITERAL_VALUE_MISMATCH
    4
    String check = "Lock Modes";
    5
    Session s1 = getSessions().openSession();
    5
    Session s1 = getSessions().openSession();
    6
    Transaction t1 = s1.beginTransaction();
    6
    Transaction t1 = s1.beginTransaction();
                                                                                                                                                                                        
    7
    Part part = new Part(new Item("EJB3 Specification"), check, "3.3.5.3", new BigDecimal(0.0));
    Preondition Violations
    Unmatched statement Part part=new Part(new Item("EJB3 Specification"),check,"3.3.5.3",new BigDecimal(0.0)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7
    Part part = new Part(new Item("EJB3 Specification"), check, "3.3.5.3", new BigDecimal(0.0));
    7
    Item item = new Item(check);
    7
    Item item = new Item(check);
    Preondition Violations
    Unmatched statement Item item=new Item(check); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                              
    8
    s1.save(item);
    8
    s1.save(item);
    8
    s1.save(part);
    Differences
    Expression1Expression2Difference
    itempartVARIABLE_NAME_MISMATCH
    org.hibernate.test.jpa.Itemorg.hibernate.test.jpa.PartVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.jpa.Item of variable item does not match with type org.hibernate.test.jpa.Part of variable part
    • Make classes org.hibernate.test.jpa.Item and org.hibernate.test.jpa.Part extend a common superclass
    8
    s1.save(part);
    9
    t1.commit();
    9
    t1.commit();
    10
    s1.close();
    10
    s1.close();
    11
    Long itemId = item.getId();
    11
    Long itemId = item.getId();
    11
    Long partId = part.getId();
    Differences
    Expression1Expression2Difference
    itemIdpartIdVARIABLE_NAME_MISMATCH
    itempartVARIABLE_NAME_MISMATCH
    org.hibernate.test.jpa.Itemorg.hibernate.test.jpa.PartVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.jpa.Item of variable item does not match with type org.hibernate.test.jpa.Part of variable part
    • Make classes org.hibernate.test.jpa.Item and org.hibernate.test.jpa.Part extend a common superclass
    11
    Long partId = part.getId();
    12
    long initialVersion = item.getVersion();
                                                                                        
    13
    s1 = getSessions().openSession();
    12
    s1 = getSessions().openSession();
    14
    t1 = s1.beginTransaction();
    13
    t1 = s1.beginTransaction();
                                                                                      
    14
    part = (Part)s1.get(Part.class, partId);
    Preondition Violations
    Unmatched statement part=(Part)s1.get(Part.class,partId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14
    part = (Part)s1.get(Part.class, partId);
    15
    item = (Item)s1.get(Item.class, itemId);
    15
    item = (Item)s1.get(Item.class, itemId);
    Preondition Violations
    Unmatched statement item=(Item)s1.get(Item.class,itemId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                      
    16
    Session s2 = getSessions().openSession();
    15
    Session s2 = getSessions().openSession();
    17
    Transaction t2 = s2.beginTransaction();
    16
    Transaction t2 = s2.beginTransaction();
                                                                                                  
    17
    Part part2 = (Part)s2.get(Part.class, partId);
    Preondition Violations
    Unmatched statement Part part2=(Part)s2.get(Part.class,partId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17
    Part part2 = (Part)s2.get(Part.class, partId);
    18
    Item item2 = (Item)s2.get(Item.class, itemId);
                                                                                                  
    19
    item2.setName("EJB3 Persistence Spec");
                                                                                          
    20
    t2.commit();
    19
    t2.commit();
    21
    s2.close();
    20
    s2.close();
                                                                                                                                              
    21
    part2 = (Part)s1.createQuery("select p from Part p").list().get(0);
    Preondition Violations
    Unmatched statement part2=(Part)s1.createQuery("select p from Part p").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21
    part2 = (Part)s1.createQuery("select p from Part p").list().get(0);
                                                                
    22
    assertTrue(part == part2);
    22
    item2 = (Item)s1.createQuery("select i from Item i").list().get(0);
    22
    item2 = (Item)s1.createQuery("select i from Item i").list().get(0);
    Preondition Violations
    Unmatched statement item2=(Item)s1.createQuery("select i from Item i").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                              
    23
    assertTrue(item == item2);
                                                                
    24
    assertEquals("encountered non-repeatable read", check, item2.getName());
    24
    assertEquals("encountered non-repeatable read", check, item2.getName());
    23
    assertEquals("encountered non-repeatable read", check, part2.getName());
    Differences
    Expression1Expression2Difference
    item2part2VARIABLE_NAME_MISMATCH
    org.hibernate.test.jpa.Itemorg.hibernate.test.jpa.PartVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.jpa.Item of variable item2 does not match with type org.hibernate.test.jpa.Part of variable part2
    • Make classes org.hibernate.test.jpa.Item and org.hibernate.test.jpa.Part extend a common superclass
    23
    assertEquals("encountered non-repeatable read", check, part2.getName());
    25
    assertEquals("encountered non-repeatable read", initialVersion, item2.getVersion());
    25
    assertEquals("encountered non-repeatable read", initialVersion, item2.getVersion());
    18
    part2.setName("Lock Mode Types");
    Differences
    Expression1Expression2Difference
    assertEqualssetNameMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals("encountered non-repeatable read",initialVersion,item2.getVersion())part2.setName("Lock Mode Types")ARGUMENT_NUMBER_MISMATCH
    part2MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals("encountered non-repeatable read",initialVersion,item2.getVersion()) is a void method call, and thus it cannot be parameterized
    Expression part2.setName("Lock Mode Types") is a void method call, and thus it cannot be parameterized
    Expression assertEquals("encountered non-repeatable read",initialVersion,item2.getVersion()) is a void method call, and thus it cannot be parameterized
    Expression part2.setName("Lock Mode Types") is a void method call, and thus it cannot be parameterized
    18
    part2.setName("Lock Mode Types");
    26
    t1.commit();
    24
    t1.commit();
    27
    s1.close();
    25
    s1.close();
    28
    s1 = getSessions().openSession();
    26
    s1 = getSessions().openSession();
    29
    t1 = s1.beginTransaction();
    27
    t1 = s1.beginTransaction();
                                              
    28
    s1.delete(part2);
                                                                  
    29
    s1.delete(part2.getItem());
    30
    s1.createQuery("delete Item").executeUpdate();
                                                                                                        
    31
    t1.commit();
    30
    t1.commit();
    32
    s1.close();
    31
    s1.close();
    Precondition Violations (15)
    Row Violation
    1Unmatched statement Part part=new Part(new Item("EJB3 Specification"),check,"3.3.5.3",new BigDecimal(0.0)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement Item item=new Item(check); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Type org.hibernate.test.jpa.Item of variable item does not match with type org.hibernate.test.jpa.Part of variable part
    4Type org.hibernate.test.jpa.Item of variable item does not match with type org.hibernate.test.jpa.Part of variable part
    5Unmatched statement part=(Part)s1.get(Part.class,partId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement item=(Item)s1.get(Item.class,itemId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched statement Part part2=(Part)s2.get(Part.class,partId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Unmatched statement part2=(Part)s1.createQuery("select p from Part p").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9Unmatched statement item2=(Item)s1.createQuery("select i from Item i").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Type org.hibernate.test.jpa.Item of variable item2 does not match with type org.hibernate.test.jpa.Part of variable part2
    11Expression assertEquals("encountered non-repeatable read",initialVersion,item2.getVersion()) is a void method call, and thus it cannot be parameterized
    12Expression part2.setName("Lock Mode Types") is a void method call, and thus it cannot be parameterized
    13Expression assertEquals("encountered non-repeatable read",initialVersion,item2.getVersion()) is a void method call, and thus it cannot be parameterized
    14Expression part2.setName("Lock Mode Types") is a void method call, and thus it cannot be parameterized
    15Clone fragment #1 returns variables check, itemId, s1, s2 , while Clone fragment #2 returns variables check, partId, s1, s2