Session session = openSession(); Transaction txn = session.beginTransaction(); Parent parent = new Parent(); Child child = new Child(); child.setParent( parent ); parent.setChildren( Collections.singleton( child ) ); session.save( parent ); txn.commit(); session.close(); session = openSession(); txn = session.beginTransaction(); parent = ( Parent ) session.get( Parent.class, parent.getId() ); assertEquals( 1, parent.getChildren().size() ); assertEquals( 0, parent.getDeleteOrphanChildren().size() ); session.delete( parent ); txn.commit(); session.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/cascade/BidirectionalOneToManyCascadeTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java
Method name: void testSaveParentWithChild() Method name: void testCascadeSave()
Number of AST nodes: 17 Number of AST nodes: 18
1
Session session = openSession();
1
Session s = openSession();
2
		Transaction txn = session.beginTransaction();
2
		Transaction t = s.beginTransaction();
3
		Parent parent = new Parent();
3
		Baz baz = new 
4
		Child child = new Child();
5
		child.setParent( parent );
6
		parent.setChildren( Collections.singleton( child ) );
7
		session.save( parent 
4
Baz();
5
		List list = new ArrayList();
6
		list.add( new Fee() );
7
		list.add( new Fee() );
8
		baz.setFees(list);
8
);
9
		s.save(baz);
9
		txn.commit();
10
		t.commit();
10
		session.close();
11
		s.close();
11
		session = openSession();
12
		s = openSession();
12
		txn = session.beginTransaction();
13
		t = s.beginTransaction();
13
		parent = ( Parent ) session.get( Parent.class, parent.getId() );
14
		baz = (Baz) s.load( Baz.class, baz.getCode() );
14
		assertEquals( 1, parent.getChildren().size() );
15
		assertTrue( baz.getFees().size()==2 );
15
		assertEquals( 0, parent.getDeleteOrphanChildren().size() );
16
		
16
		session.delete( parent
17
s.delete(baz);
17
 );
18
		assertTrue( !s.iterate("from Fee fee").hasNext() );
18
		txn.commit();
19
		t.commit();
19
		session.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 comparisons234
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements11
    Number of unmapped statements in the first code fragment6
    Number of unmapped statements in the second code fragment7
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    Session session = openSession();
    1
    Session session = openSession();
    1
    Session s = openSession();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    sessionsVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    1
    Session s = openSession();
    2
    Transaction txn = session.beginTransaction();
    2
    Transaction txn = session.beginTransaction();
    2
    Transaction t = s.beginTransaction();
    Differences
    Expression1Expression2Difference
    txntVARIABLE_NAME_MISMATCH
    sessionsVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    2
    Transaction t = s.beginTransaction();
                                              
    3
    Baz baz = new Baz();
    3
    Parent parent = new Parent();
                                                                
                                                              
    4
    List list = new ArrayList();
    4
    Child child = new Child();
                                                          
                                                  
    5
    list.add(new Fee());
    5
    child.setParent(parent);
    5
    child.setParent(parent);
    Preondition Violations
    Unmatched statement child.setParent(parent); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                          
                                                  
    6
    list.add(new Fee());
    6
    parent.setChildren(Collections.singleton(child));
    6
    parent.setChildren(Collections.singleton(child));
    Preondition Violations
    Unmatched statement parent.setChildren(Collections.singleton(child)); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                            
                                              
    7
    baz.setFees(list);
    Preondition Violations
    Unmatched statement baz.setFees(list); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    7
    baz.setFees(list);
    7
    session.save(parent);
    7
    session.save(parent);
    8
    s.save(baz);
    Differences
    Expression1Expression2Difference
    parentbazVARIABLE_NAME_MISMATCH
    org.hibernate.test.cascade.Parentorg.hibernate.test.legacy.BazVARIABLE_TYPE_MISMATCH
    sessionsVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cascade.Parent of variable parent does not match with type org.hibernate.test.legacy.Baz of variable baz
    • Make classes org.hibernate.test.cascade.Parent and org.hibernate.test.legacy.Baz extend a common superclass
    8
    s.save(baz);
    8
    txn.commit();
    8
    txn.commit();
    9
    t.commit();
    Differences
    Expression1Expression2Difference
    txntVARIABLE_NAME_MISMATCH
    9
    t.commit();
    9
    session.close();
    9
    session.close();
    10
    s.close();
    Differences
    Expression1Expression2Difference
    sessionsVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    10
    s.close();
    10
    session = openSession();
    10
    session = openSession();
    11
    s = openSession();
    Differences
    Expression1Expression2Difference
    sessionsVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    11
    s = openSession();
    11
    txn = session.beginTransaction();
    11
    txn = session.beginTransaction();
    12
    t = s.beginTransaction();
    Differences
    Expression1Expression2Difference
    txntVARIABLE_NAME_MISMATCH
    sessionsVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    12
    t = s.beginTransaction();
    12
    parent = (Parent)session.get(Parent.class, parent.getId());
    12
    parent = (Parent)session.get(Parent.class, parent.getId());
    Preondition Violations
    Unmatched statement parent=(Parent)session.get(Parent.class,parent.getId()); 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());
    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());
    13
    assertEquals(1, parent.getChildren().size());
    13
    assertEquals(1, parent.getChildren().size());
    14
    assertTrue(baz.getFees().size() == 2);
    Differences
    Expression1Expression2Difference
    assertEqualsassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,parent.getChildren().size())assertTrue(baz.getFees().size() == 2)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(1,parent.getChildren().size()) 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 assertEquals(1,parent.getChildren().size()) 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 assertEquals(1,parent.getChildren().size()) 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 assertEquals(1,parent.getChildren().size()) 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);
    14
    assertEquals(0, parent.getDeleteOrphanChildren().size());
                                                                                                                            
    15
    session.delete(parent);
    15
    session.delete(parent);
    15
    s.delete(baz);
    Differences
    Expression1Expression2Difference
    parentbazVARIABLE_NAME_MISMATCH
    org.hibernate.test.cascade.Parentorg.hibernate.test.legacy.BazVARIABLE_TYPE_MISMATCH
    sessionsVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cascade.Parent of variable parent does not match with type org.hibernate.test.legacy.Baz of variable baz
    • Make classes org.hibernate.test.cascade.Parent and org.hibernate.test.legacy.Baz extend a common superclass
    15
    s.delete(baz);
                                                                                                              
    16
    assertTrue(!s.iterate("from Fee fee").hasNext());
    Preondition Violations
    Unmatched statement assertTrue(!s.iterate("from Fee fee").hasNext()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16
    assertTrue(!s.iterate("from Fee fee").hasNext());
    16
    txn.commit();
    16
    txn.commit();
    17
    t.commit();
    Differences
    Expression1Expression2Difference
    txntVARIABLE_NAME_MISMATCH
    17
    t.commit();
    17
    session.close();
    17
    session.close();
    18
    s.close();
    Differences
    Expression1Expression2Difference
    sessionsVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    18
    s.close();
    Precondition Violations (17)
    Row Violation
    1Unmatched statement child.setParent(parent); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement parent.setChildren(Collections.singleton(child)); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement baz.setFees(list); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Type org.hibernate.test.cascade.Parent of variable parent does not match with type org.hibernate.test.legacy.Baz of variable baz
    5Unmatched statement parent=(Parent)session.get(Parent.class,parent.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched 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
    7Expression assertEquals(1,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression assertTrue(baz.getFees().size() == 2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    10Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized
    11Expression assertEquals(1,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression assertTrue(baz.getFees().size() == 2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    14Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized
    15Type org.hibernate.test.cascade.Parent of variable parent does not match with type org.hibernate.test.legacy.Baz of variable baz
    16Unmatched statement assertTrue(!s.iterate("from Fee fee").hasNext()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17Clone fragment #1 returns variable session with type org.hibernate.Session , while Clone fragment #2 returns variable s with type org.hibernate.classic.Session