Contract c = new Contract("gavin", "phone"); ContractVariation cv1 = new ContractVariation(1, c); cv1.setText("expensive"); ContractVariation cv2 = new ContractVariation(2, c); cv2.setText("more expensive"); Session s = openSession(); Transaction t = s.beginTransaction(); s.persist(c); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); c.setCustomerName("foo bar"); s.update( c ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); c = (Contract) s.createCriteria(Contract.class).uniqueResult(); assertEquals( c.getCustomerName(), "gavin" ); assertEquals( c.getVariations().size(), 2 ); Iterator it = c.getVariations().iterator(); cv1 = (ContractVariation) it.next(); assertEquals( cv1.getText(), "expensive" ); cv2 = (ContractVariation) it.next(); assertEquals( cv2.getText(), "more expensive" ); s.delete(c); assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) ); assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) ); t.commit(); s.close();
Contract c = new Contract("gavin", "phone"); ContractVariation cv1 = new ContractVariation(1, c); cv1.setText("expensive"); ContractVariation cv2 = new ContractVariation(2, c); cv2.setText("more expensive"); Session s = openSession(); Transaction t = s.beginTransaction(); s.persist(c); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); c.setCustomerName("foo bar"); s.merge( c ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); c = (Contract) s.createCriteria(Contract.class).uniqueResult(); assertEquals( c.getCustomerName(), "gavin" ); assertEquals( c.getVariations().size(), 2 ); Iterator it = c.getVariations().iterator(); cv1 = (ContractVariation) it.next(); assertEquals( cv1.getText(), "expensive" ); cv2 = (ContractVariation) it.next(); assertEquals( cv2.getText(), "more expensive" ); s.delete(c); assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) ); assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) ); t.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/immutable/ImmutableTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/immutable/ImmutableTest.java
Method name: void testImmutableParentEntityWithUpdate() Method name: void testImmutableParentEntityWithMerge()
Number of AST nodes: 31 Number of AST nodes: 31
1
Contract c = new Contract("gavin", "phone");
1
Contract c = new Contract("gavin", "phone");
2
		ContractVariation cv1 = new ContractVariation(1, c);
2
		ContractVariation cv1 = new ContractVariation(1, c);
3
		cv1.setText("expensive");
3
		cv1.setText("expensive");
4
		ContractVariation cv2 = new ContractVariation(2, c);
4
		ContractVariation cv2 = new ContractVariation(2, c);
5
		cv2.setText("more expensive");
5
		cv2.setText("more expensive");
6
		Session s = openSession();
6
		Session s = openSession();
7
		Transaction t = s.beginTransaction();
7
		Transaction t = s.beginTransaction();
8
		s.persist(c);
8
		s.persist(c);
9
		t.commit();
9
		t.commit();
10
		s.close();
10
		s.close();
11
		s = openSession();
11
		s = openSession();
12
		t = s.beginTransaction();
12
		t = s.beginTransaction();
13
		c.setCustomerName("foo bar");
13
		c.setCustomerName("foo bar");
14
		s.update( c );
14
		s.merge( c );
15
		t.commit();
15
		t.commit();
16
		s.close();
16
		s.close();
17
		s = openSession();
17
		s = openSession();
18
		t = s.beginTransaction();
18
		t = s.beginTransaction();
19
		c = (Contract) s.createCriteria(Contract.class).uniqueResult();
19
		c = (Contract) s.createCriteria(Contract.class).uniqueResult();
20
		assertEquals( c.getCustomerName(), "gavin" );
20
		assertEquals( c.getCustomerName(), "gavin" );
21
		assertEquals( c.getVariations().size(), 2 );
21
		assertEquals( c.getVariations().size(), 2 );
22
		Iterator it = c.getVariations().iterator();
22
		Iterator it = c.getVariations().iterator();
23
		cv1 = (ContractVariation) it.next();
23
		cv1 = (ContractVariation) it.next();
24
		assertEquals( cv1.getText(), "expensive" );
24
		assertEquals( cv1.getText(), "expensive" );
25
		cv2 = (ContractVariation) it.next();
25
		cv2 = (ContractVariation) it.next();
26
		assertEquals( cv2.getText(), "more expensive" );
26
		assertEquals( cv2.getText(), "more expensive" );
27
		s.delete(c);
27
		s.delete(c);
28
		assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
28
		assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
29
		assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
29
		assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
30
		t.commit();
30
		t.commit();
31
		s.close();
31
		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 comparisons269
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements30
    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
    Contract c = new Contract("gavin", "phone");
    1
    Contract c = new Contract("gavin", "phone");
    2
    ContractVariation cv1 = new ContractVariation(1, c);
    2
    ContractVariation cv1 = new ContractVariation(1, c);
    3
    cv1.setText("expensive");
    3
    cv1.setText("expensive");
    4
    ContractVariation cv2 = new ContractVariation(2, c);
    4
    ContractVariation cv2 = new ContractVariation(2, c);
    5
    cv2.setText("more expensive");
    5
    cv2.setText("more expensive");
    6
    Session s = openSession();
    6
    Session s = openSession();
    7
    Transaction t = s.beginTransaction();
    7
    Transaction t = s.beginTransaction();
    8
    s.persist(c);
    8
    s.persist(c);
    9
    t.commit();
    9
    t.commit();
    10
    s.close();
    10
    s.close();
    11
    s = openSession();
    11
    s = openSession();
    12
    t = s.beginTransaction();
    12
    t = s.beginTransaction();
    13
    c.setCustomerName("foo bar");
    13
    c.setCustomerName("foo bar");
                                  
    14
    s.merge(c);
    Preondition Violations
    Unmatched statement s.merge(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14
    s.merge(c);
    14
    s.update(c);
    14
    s.update(c);
    Preondition Violations
    Unmatched statement s.update(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                    
    15
    t.commit();
    15
    t.commit();
    16
    s.close();
    16
    s.close();
    17
    s = openSession();
    17
    s = openSession();
    18
    t = s.beginTransaction();
    18
    t = s.beginTransaction();
    19
    c = (Contract)s.createCriteria(Contract.class).uniqueResult();
    19
    c = (Contract)s.createCriteria(Contract.class).uniqueResult();
    20
    assertEquals(c.getCustomerName(), "gavin");
    20
    assertEquals(c.getCustomerName(), "gavin");
    21
    assertEquals(c.getVariations().size(), 2);
    21
    assertEquals(c.getVariations().size(), 2);
    22
    Iterator it = c.getVariations().iterator();
    22
    Iterator it = c.getVariations().iterator();
    23
    cv1 = (ContractVariation)it.next();
    23
    cv1 = (ContractVariation)it.next();
    24
    assertEquals(cv1.getText(), "expensive");
    24
    assertEquals(cv1.getText(), "expensive");
    25
    cv2 = (ContractVariation)it.next();
    25
    cv2 = (ContractVariation)it.next();
    26
    assertEquals(cv2.getText(), "more expensive");
    26
    assertEquals(cv2.getText(), "more expensive");
    27
    s.delete(c);
    27
    s.delete(c);
    28
    assertEquals(s.createCriteria(Contract.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0));
    28
    assertEquals(s.createCriteria(Contract.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0));
    29
    assertEquals(s.createCriteria(ContractVariation.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0));
    29
    assertEquals(s.createCriteria(ContractVariation.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0));
    30
    t.commit();
    30
    t.commit();
    31
    s.close();
    31
    s.close();
    Precondition Violations (2)
    Row Violation
    1Unmatched statement s.merge(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement s.update(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted