Session s = openSession(); Transaction t = s.beginTransaction(); Address address = new Address(); address.setInfo( "123 Main St." ); s.save( address ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); Person p = new Person(); p.getAddresses().add( address ); s.delete( p ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); Long count = ( Long ) s.createQuery( "select count(*) from Address" ).list().get( 0 ); assertEquals( "delete not cascaded properly across transient entity", 0, count.longValue() ); t.commit(); s.close();
Session s = openSession(); Transaction t = s.beginTransaction(); Baz baz = new Baz(); List list = new ArrayList(); list.add( new Fee() ); list.add( new Fee() ); baz.setFees(list); s.save(baz); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); baz = (Baz) s.load( Baz.class, baz.getCode() ); assertTrue( baz.getFees().size()==2 ); s.delete(baz); assertTrue( !s.iterate("from Fee fee").hasNext() ); 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/deletetransient/DeleteTransientEntityTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java
Method name: void testTransientEntityDeletionCascadingToDetachedAssociation() Method name: void testCascadeSave()
Number of AST nodes: 20 Number of AST nodes: 18
1
Session s = openSession();
1
Session s = openSession();
2
		Transaction t = s.beginTransaction();
2
		Transaction t = s.beginTransaction();
3
		Address address = new Address();
3
		Baz baz = new Baz();
4
		address.setInfo( "123 Main St." );
4
		
5
		s.save( address );
6
		t.commit();
5
List list = new ArrayList();
7
		s.close();
6
		
8
		s = openSession();
9
		t = s.beginTransaction();
10
		Person p = new Person(
7
list.add( new Fee() );
11
);
8
		list.add( new Fee() );
12
		p.getAddresses().add( address );
9
		baz.setFees(list);
13
		s.delete( p );
10
		s.save(baz);
14
		t.commit();
11
		t.commit();
15
		s.close();
12
		s.close();
16

17
		s = openSession();
13
		s = openSession();
18
		t = s.beginTransaction();
14
		t = s.beginTransaction();
19
		Long count = ( Long ) s.createQuery( "select count(*) from Address" ).list().get( 0 );
15
		baz = (Baz) s.load( Baz.class, baz.getCode() );
20
		assertEquals( "delete not cascaded properly across transient entity", 0, count.longValue
16
		assertTrue( baz.getFees().size()==2 );
17
		s.delete(baz);
21
() );
18
		assertTrue( !s.iterate("from Fee fee").hasNext() );
22
		t.commit();
19
		t.commit();
23
		s.close();
20
		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 in different classes having the same super class
Number of node comparisons225
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements10
    Number of unmapped statements in the first code fragment10
    Number of unmapped statements in the second code fragment8
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                          
    1
    Session s = openSession();
    1
    Session s = openSession();
                                                          
    2
    Transaction t = s.beginTransaction();
    2
    Transaction t = s.beginTransaction();
    2
    Transaction t = s.beginTransaction();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    2
    Transaction t = s.beginTransaction();
                                              
    3
    Baz baz = new Baz();
    3
    Address address = new Address();
                                                                      
                                                              
    4
    List list = new ArrayList();
    4
    address.setInfo("123 Main St.");
                                                                          
                                                  
    5
    list.add(new Fee());
                                                  
    6
    list.add(new Fee());
    5
    s.save(address);
    5
    s.save(address);
    8
    s.save(baz);
    Differences
    Expression1Expression2Difference
    addressbazVARIABLE_NAME_MISMATCH
    org.hibernate.test.deletetransient.Addressorg.hibernate.test.legacy.BazVARIABLE_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.deletetransient.Address of variable address does not match with type org.hibernate.test.legacy.Baz of variable baz
    • Make classes org.hibernate.test.deletetransient.Address and org.hibernate.test.legacy.Baz extend a common superclass
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    8
    s.save(baz);
    6
    t.commit();
    9
    t.commit();
    7
    s.close();
    7
    s.close();
    10
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    10
    s.close();
    8
    s = openSession();
    8
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                          
                                            
    11
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11
    s = openSession();
    9
    t = s.beginTransaction();
    9
    t = s.beginTransaction();
    12
    t = s.beginTransaction();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    12
    t = s.beginTransaction();
    10
    Person p = new Person();
                                                        
    11
    p.getAddresses().add(address);
                                                                        
                                                                                              
    13
    baz = (Baz)s.load(Baz.class, baz.getCode());
    Preondition Violations
    Unmatched statement baz=(Baz)s.load(Baz.class,baz.getCode()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13
    baz = (Baz)s.load(Baz.class, baz.getCode());
    12
    s.delete(p);
    12
    s.delete(p);
    15
    s.delete(baz);
    Differences
    Expression1Expression2Difference
    pbazVARIABLE_NAME_MISMATCH
    org.hibernate.test.deletetransient.Personorg.hibernate.test.legacy.BazVARIABLE_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.deletetransient.Person of variable p does not match with type org.hibernate.test.legacy.Baz of variable baz
    • Make classes org.hibernate.test.deletetransient.Person and org.hibernate.test.legacy.Baz extend a common superclass
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    15
    s.delete(baz);
                                                                                                              
    16
    assertTrue(!s.iterate("from Fee fee").hasNext());
    13
    t.commit();
    17
    t.commit();
    14
    s.close();
                                
    15
    s = openSession();
    15
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                            
    16
    t = s.beginTransaction();
    16
    t = s.beginTransaction();
    Preondition Violations
    Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                          
    17
    Long count = (Long)s.createQuery("select count(*) from Address").list().get(0);
                                                                                                                                                                      
    18
    assertEquals("delete not cascaded properly across transient entity", 0, count.longValue());
    18
    assertEquals("delete not cascaded properly across transient entity", 0, count.longValue());
    7
    baz.setFees(list);
    Differences
    Expression1Expression2Difference
    assertEqualssetFeesMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals("delete not cascaded properly across transient entity",0,count.longValue())baz.setFees(list)ARGUMENT_NUMBER_MISMATCH
    bazMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals("delete not cascaded properly across transient entity",0,count.longValue()) is a void method call, and thus it cannot be parameterized
    Expression baz.setFees(list) is a void method call, and thus it cannot be parameterized
    Expression assertEquals("delete not cascaded properly across transient entity",0,count.longValue()) is a void method call, and thus it cannot be parameterized
    Expression baz.setFees(list) is a void method call, and thus it cannot be parameterized
    7
    baz.setFees(list);
    19
    t.commit();
    19
    t.commit();
    14
    assertTrue(baz.getFees().size() == 2);
    Differences
    Expression1Expression2Difference
    commitassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    t.commit()assertTrue(baz.getFees().size() == 2)ARGUMENT_NUMBER_MISMATCH
    tMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(baz.getFees().size() == 2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression t.commit() is a void method call, and thus it cannot be parameterized
    Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized
    Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(baz.getFees().size() == 2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression t.commit() is a void method call, and thus it cannot be parameterized
    Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized
    14
    assertTrue(baz.getFees().size() == 2);
    20
    s.close();
    20
    s.close();
    18
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    18
    s.close();
    Precondition Violations (25)
    Row Violation
    1Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    2Type org.hibernate.test.deletetransient.Address of variable address does not match with type org.hibernate.test.legacy.Baz of variable baz
    3Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    4Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    5Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    8Unmatched statement baz=(Baz)s.load(Baz.class,baz.getCode()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9Type org.hibernate.test.deletetransient.Person of variable p does not match with type org.hibernate.test.legacy.Baz of variable baz
    10Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    11Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Expression assertEquals("delete not cascaded properly across transient entity",0,count.longValue()) is a void method call, and thus it cannot be parameterized
    14Expression baz.setFees(list) is a void method call, and thus it cannot be parameterized
    15Expression assertEquals("delete not cascaded properly across transient entity",0,count.longValue()) is a void method call, and thus it cannot be parameterized
    16Expression baz.setFees(list) is a void method call, and thus it cannot be parameterized
    17Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression assertTrue(baz.getFees().size() == 2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19Expression t.commit() is a void method call, and thus it cannot be parameterized
    20Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized
    21Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression assertTrue(baz.getFees().size() == 2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23Expression t.commit() is a void method call, and thus it cannot be parameterized
    24Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized
    25Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s