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 comparisons231
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements10
    Number of unmapped statements in the first code fragment7
    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 session = 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.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable session 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
    Parent parent = new Parent();
                                                                
                                                              
    4
    List list = new ArrayList();
    4
    Child child = new Child();
                                                          
                                                  
    5
    list.add(new Fee());
    5
    child.setParent(parent);
                                                          
                                                  
    6
    list.add(new Fee());
    6
    parent.setChildren(Collections.singleton(child));
                                                                                                            
                                              
    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.SessionVARIABLE_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
    Type org.hibernate.Session of variable session 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);
    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.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable session 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();
    10
    session = openSession();
    10
    session = openSession();
    Preondition Violations
    Unmatched statement session=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();
    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.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable session 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();
    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());
    16
    assertTrue(!s.iterate("from Fee fee").hasNext());
    Differences
    Expression1Expression2Difference
    assertEqualsassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(1,parent.getChildren().size())assertTrue(!s.iterate("from Fee fee").hasNext())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(!s.iterate("from Fee fee").hasNext()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(!s.iterate("from Fee fee").hasNext()) is a void method call, and thus it cannot be parameterized
    16
    assertTrue(!s.iterate("from Fee fee").hasNext());
    14
    assertEquals(0, parent.getDeleteOrphanChildren().size());
    14
    assertEquals(0, parent.getDeleteOrphanChildren().size());
    14
    assertTrue(baz.getFees().size() == 2);
    Differences
    Expression1Expression2Difference
    assertEqualsassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(0,parent.getDeleteOrphanChildren().size())assertTrue(baz.getFees().size() == 2)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(0,parent.getDeleteOrphanChildren().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(0,parent.getDeleteOrphanChildren().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);
    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.SessionVARIABLE_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
    Type org.hibernate.Session of variable session 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
    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.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable session 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 (20)
    Row Violation
    1Type org.hibernate.Session of variable session does not match with type org.hibernate.classic.Session of variable s
    2Type org.hibernate.test.cascade.Parent of variable parent does not match with type org.hibernate.test.legacy.Baz of variable baz
    3Type org.hibernate.Session of variable session does not match with type org.hibernate.classic.Session of variable s
    4Type org.hibernate.Session of variable session does not match with type org.hibernate.classic.Session of variable s
    5Unmatched statement session=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 session does not match with type org.hibernate.classic.Session of variable s
    8Unmatched 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
    9Unmatched 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
    10Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    11Expression assertTrue(!s.iterate("from Fee fee").hasNext()) is a void method call, and thus it cannot be parameterized
    12Expression assertEquals(1,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    13Expression assertTrue(!s.iterate("from Fee fee").hasNext()) is a void method call, and thus it cannot be parameterized
    14Expression assertEquals(0,parent.getDeleteOrphanChildren().size()) is a void method call, and thus it cannot be parameterized
    15Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized
    16Expression assertEquals(0,parent.getDeleteOrphanChildren().size()) is a void method call, and thus it cannot be parameterized
    17Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized
    18Type org.hibernate.test.cascade.Parent of variable parent does not match with type org.hibernate.test.legacy.Baz of variable baz
    19Type org.hibernate.Session of variable session does not match with type org.hibernate.classic.Session of variable s
    20Type org.hibernate.Session of variable session does not match with type org.hibernate.classic.Session of variable s