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 aLoaded = ( A ) s.load( A.class, new Long( a.getId() ) ); assertTrue( aLoaded instanceof HibernateProxy ); assertSame( aLoaded, s.merge( a ) ); s.getTransaction().commit(); s.close(); verifyModifications( a.getId() );
Session s = openSession(); Bar bar = new Bar(); s.save(bar); bar.setBarString("bar bar"); s.flush(); s.connection().commit(); s.close(); s = openSession(); FooProxy foo = (FooProxy) s.load( Foo.class, bar.getKey() ); assertTrue( "polymorphic", foo instanceof BarProxy ); assertTrue( "subclass property", ( (BarProxy) foo ).getBarString().equals( bar.getBarString() ) ); //System.out.println( s.print(foo) ); s.delete(foo); s.flush(); s.connection().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/legacy/FooBarTest.java
Method name: void testMultiPathMergeModifiedDetachedIntoProxy() Method name: void testPolymorphism()
Number of AST nodes: 16 Number of AST nodes: 15
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		
3
		A a = new A(
3
Bar bar = new Bar();
4
);
4
		s.save(bar);
5
		a.setData( "Anna" );
5
		bar.set
6
		s.save( a );
7
		s.getTransaction().commit();
8
		s.close();
9
		// modify detached entity
10
		modifyEntity( a );
11
		s = openSession();
12
		s.beginTransaction();
13
		A aLoaded = ( A 
6
BarString("bar bar");
7
		s.flush();
8
		s.connection().commit();
9
		s.close();
10
		s = openSession();
14
) s.load( A.class, new Long( a.getId() ) );
11
		FooProxy foo = (FooProxy) s.load( Foo.class, bar.getKey() );
15
		assertTrue( aLoaded instanceof HibernateProxy );
12
		assertTrue( "polymorphic", foo instanceof BarProxy );
16
		assertSame( aLoaded, s.merge( a ) );
13
		assert
17
		s.getTransaction().commit();
18
		s.close(
14
True( "subclass property", ( (BarProxy) foo ).getBarString().equals( bar.getBarString() ) );
15
		//System.out.println( s.print(foo) );
19
);
16
		s.delete(foo);
20
		verifyModifications( a.getId() 
17
		s.flush();
18
		s.connection().commit();
21
);
19
		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 comparisons186
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements9
    Number of unmapped statements in the first code fragment7
    Number of unmapped statements in the second code fragment6
    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();
    1
    Session s = openSession();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    1
    Session s = openSession();
                                              
    2
    Bar bar = new Bar();
    2
    s.beginTransaction();
    2
    s.beginTransaction();
    Preondition Violations
    Unmatched statement s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                    
    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
    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);
    3
    s.save(bar);
    Differences
    Expression1Expression2Difference
    abarVARIABLE_NAME_MISMATCH
    org.hibernate.test.cascade.Aorg.hibernate.test.legacy.BarVARIABLE_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cascade.A of variable a does not match with type org.hibernate.test.legacy.Bar of variable bar
    • Make classes org.hibernate.test.cascade.A and org.hibernate.test.legacy.Bar extend a common superclass
    3
    s.save(bar);
                                                                  
    4
    bar.setBarString("bar bar");
    Preondition Violations
    Unmatched statement bar.setBarString("bar bar"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4
    bar.setBarString("bar bar");
                              
    5
    s.flush();
    Preondition Violations
    Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5
    s.flush();
    6
    s.getTransaction().commit();
    6
    s.getTransaction().commit();
    6
    s.connection().commit();
    Differences
    Expression1Expression2Difference
    getTransactionconnectionMETHOD_INVOCATION_NAME_MISMATCH
    org.hibernate.Transactionjava.sql.ConnectionVARIABLE_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.connection() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Type org.hibernate.Transaction of variable s.getTransaction() does not match with type java.sql.Connection of variable s.connection()
    • Make classes org.hibernate.Transaction and java.sql.Connection extend a common superclass
    6
    s.connection().commit();
    7
    s.close();
    7
    s.close();
    7
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    7
    s.close();
    8
    modifyEntity(a);
    8
    modifyEntity(a);
    11
    assertTrue("subclass property", ((BarProxy)foo).getBarString().equals(bar.getBarString()));
    Differences
    Expression1Expression2Difference
    modifyEntityassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    modifyEntity(a)assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString()))TYPE_COMPATIBLE_REPLACEMENT
    modifyEntity(a)assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString()))ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method modifyEntity
    Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) is a void method call, and thus it cannot be parameterized
    Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method modifyEntity
    Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) is a void method call, and thus it cannot be parameterized
    11
    assertTrue("subclass property", ((BarProxy)foo).getBarString().equals(bar.getBarString()));
    9
    s = openSession();
    9
    s = openSession();
    8
    s = openSession();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    8
    s = openSession();
                                                                                                                      
    9
    FooProxy foo = (FooProxy)s.load(Foo.class, bar.getKey());
    Preondition Violations
    Unmatched statement FooProxy foo=(FooProxy)s.load(Foo.class,bar.getKey()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9
    FooProxy foo = (FooProxy)s.load(Foo.class, bar.getKey());
    10
    s.beginTransaction();
    10
    s.beginTransaction();
    Preondition Violations
    Unmatched statement s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                      
    11
    A aLoaded = (A)s.load(A.class, new Long(a.getId()));
    11
    A aLoaded = (A)s.load(A.class, new Long(a.getId()));
    Preondition Violations
    Unmatched statement A aLoaded=(A)s.load(A.class,new Long(a.getId())); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                              
    12
    assertTrue(aLoaded instanceof HibernateProxy);
    12
    assertTrue(aLoaded instanceof HibernateProxy);
    10
    assertTrue("polymorphic", foo instanceof BarProxy);
    Differences
    Expression1Expression2Difference
    assertTrue(aLoaded instanceof HibernateProxy)assertTrue("polymorphic",foo instanceof BarProxy)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertTrue(aLoaded instanceof HibernateProxy) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue("polymorphic",foo instanceof BarProxy) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(aLoaded instanceof HibernateProxy) is a void method call, and thus it cannot be parameterized
    Expression assertTrue("polymorphic",foo instanceof BarProxy) is a void method call, and thus it cannot be parameterized
    10
    assertTrue("polymorphic", foo instanceof BarProxy);
                                        
    12
    s.delete(foo);
    Preondition Violations
    Unmatched statement s.delete(foo); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    s.delete(foo);
                                
    13
    s.flush();
    Preondition Violations
    Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13
    s.flush();
    13
    assertSame(aLoaded, s.merge(a));
    13
    assertSame(aLoaded, s.merge(a));
    Preondition Violations
    Unmatched statement assertSame(aLoaded,s.merge(a)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                          
    14
    s.getTransaction().commit();
    14
    s.getTransaction().commit();
    14
    s.connection().commit();
    Differences
    Expression1Expression2Difference
    getTransactionconnectionMETHOD_INVOCATION_NAME_MISMATCH
    org.hibernate.Transactionjava.sql.ConnectionVARIABLE_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.connection() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Type org.hibernate.Transaction of variable s.getTransaction() does not match with type java.sql.Connection of variable s.connection()
    • Make classes org.hibernate.Transaction and java.sql.Connection extend a common superclass
    14
    s.connection().commit();
    15
    s.close();
    15
    s.close();
    15
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    15
    s.close();
    16
    verifyModifications(a.getId());
                                                                          
    Precondition Violations (31)
    Row Violation
    1Unmatched statement s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement A a=new A(); 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.legacy.Bar of variable bar
    5Unmatched statement bar.setBarString("bar bar"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    6Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression s.connection() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Type org.hibernate.Transaction of variable s.getTransaction() does not match with type java.sql.Connection of variable s.connection()
    10Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    13Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) is a void method call, and thus it cannot be parameterized
    14Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    17Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) is a void method call, and thus it cannot be parameterized
    18Unmatched statement FooProxy foo=(FooProxy)s.load(Foo.class,bar.getKey()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19Unmatched statement s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    20Unmatched statement A aLoaded=(A)s.load(A.class,new Long(a.getId())); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Expression assertTrue(aLoaded instanceof HibernateProxy) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression assertTrue("polymorphic",foo instanceof BarProxy) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23Expression assertTrue(aLoaded instanceof HibernateProxy) is a void method call, and thus it cannot be parameterized
    24Expression assertTrue("polymorphic",foo instanceof BarProxy) is a void method call, and thus it cannot be parameterized
    25Unmatched statement s.delete(foo); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    26Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    27Unmatched statement assertSame(aLoaded,s.merge(a)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    28Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    29Expression s.connection() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    30Type org.hibernate.Transaction of variable s.getTransaction() does not match with type java.sql.Connection of variable s.connection()
    31Clone fragment #1 returns variable s with type org.hibernate.Session , while Clone fragment #2 returns variable s with type org.hibernate.classic.Session