Session s = openSession(); s.beginTransaction(); A a = new A(); a.setData( "Anna" ); s.save( a ); s.getTransaction().commit(); s.close(); // modify detached entity modifyEntity( a ); s = openSession(); s.beginTransaction(); a = ( A ) s.merge( a ); s.getTransaction().commit(); s.close(); verifyModifications( a.getId() );
Session s = openSession(); s.beginTransaction(); Person me = new Person(); me.name = "Steve"; s.save( me ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); me = ( Person ) s.load( Person.class, me.name ); assertNull( me.address ); s.delete( me ); s.getTransaction().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/MultiPathCascadeTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/onetoone/optional/OptionalOneToOneTest.java
Method name: void testMultiPathMergeModifiedDetached() Method name: void testOptionalOneToOneRetrieval()
Number of AST nodes: 14 Number of AST nodes: 14
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		s.beginTransaction();
3
		A a = new A();
3
		Person me = new Person();
4
		a.setData( "Anna" );
4
		me.name = "Steve";
5
		s.save( a );
5
		s.save( me );
6
		s.getTransaction().commit();
6
		s.getTransaction().commit();
7
		s.close();
7
		s.close();
8
		// modify detached entity
9
		modifyEntity( a );
8

10
		s = openSession();
9
		s = openSession();
11
		s.beginTransaction();
10
		s.beginTransaction();
12
		a = ( A ) s.merg
11
		me = ( Person ) s.load( Person.class, me.name );
12
		assertNull( me.address );
13
e( a );
13
		s.delete( me );
14
		s.getTransaction().commit();
14
		s.getTransaction().commit();
15
		s.close();
15
		s.close();
16
		verifyModifications( a.getId() );
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 comparisons76
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements9
    Number of unmapped statements in the first code fragment5
    Number of unmapped statements in the second code fragment5
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
    2
    s.beginTransaction();
    2
    s.beginTransaction();
                                                        
    3
    Person me = new Person();
    3
    A a = new A();
    3
    A a = new A();
    Preondition Violations
    Unmatched statement A a=new A(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                  
                                          
    4
    me.name = "Steve";
    Preondition Violations
    Unmatched statement me.name="Steve"; cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4
    me.name = "Steve";
    4
    a.setData("Anna");
    4
    a.setData("Anna");
    Preondition Violations
    Unmatched statement a.setData("Anna"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                              
    5
    s.save(a);
    5
    s.save(a);
    5
    s.save(me);
    Differences
    Expression1Expression2Difference
    ameVARIABLE_NAME_MISMATCH
    org.hibernate.test.cascade.Aorg.hibernate.test.onetoone.optional.PersonVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cascade.A of variable a does not match with type org.hibernate.test.onetoone.optional.Person of variable me
    • Make classes org.hibernate.test.cascade.A and org.hibernate.test.onetoone.optional.Person extend a common superclass
    5
    s.save(me);
    6
    s.getTransaction().commit();
    6
    s.getTransaction().commit();
    7
    s.close();
    7
    s.close();
    8
    modifyEntity(a);
    8
    modifyEntity(a);
    Preondition Violations
    Unmatched statement modifyEntity(a); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                          
    9
    s = openSession();
    8
    s = openSession();
    10
    s.beginTransaction();
    9
    s.beginTransaction();
                                                                                            
    10
    me = (Person)s.load(Person.class, me.name);
    Preondition Violations
    Unmatched statement me=(Person)s.load(Person.class,me.name); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10
    me = (Person)s.load(Person.class, me.name);
                                                          
    11
    assertNull(me.address);
    11
    a = (A)s.merge(a);
    11
    a = (A)s.merge(a);
    Preondition Violations
    Unmatched statement a=(A)s.merge(a); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                            
                                      
    12
    s.delete(me);
    Preondition Violations
    Unmatched statement s.delete(me); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    s.delete(me);
    12
    s.getTransaction().commit();
    13
    s.getTransaction().commit();
    13
    s.close();
    14
    s.close();
    14
    verifyModifications(a.getId());
                                                                          
    Precondition Violations (8)
    Row Violation
    1Unmatched statement A a=new A(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement me.name="Steve"; cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement a.setData("Anna"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Type org.hibernate.test.cascade.A of variable a does not match with type org.hibernate.test.onetoone.optional.Person of variable me
    5Unmatched statement modifyEntity(a); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    6Unmatched statement me=(Person)s.load(Person.class,me.name); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched statement a=(A)s.merge(a); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Unmatched statement s.delete(me); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted