Session s = openSession(); Vetoer v = new Vetoer(); v.setStrings( new String[] { "foo", "bar", "baz" } ); s.save(v); Serializable id = s.save(v); v.getStrings()[1] = "osama"; s.flush(); s.connection().commit(); s.close(); s = openSession(); v = (Vetoer) s.load(Vetoer.class, id); assertTrue( "serializable type", v.getStrings()[1].equals("osama") ); s.delete(v); s.delete(v); s.flush(); s.connection().commit(); s.close();
Customer cust = new Customer(); cust.setCustomerId("xyz123"); cust.setName("Matt"); Session s = openSession(); Transaction t = s.beginTransaction(); s.persist(cust); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); List results = s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list(); //List results = s.createQuery("from Customer cust left join fetch cust.billingAddress left join fetch cust.shippingAddress").list(); cust = (Customer) results.get(0); assertNull( cust.getShippingAddress() ); assertNull( cust.getBillingAddress() ); s.delete( cust ); 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/legacy/FooBarTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/typedmanytoone/TypedManyToOneTest.java
Method name: void testSerializableType() Method name: void testCreateQueryNull()
Number of AST nodes: 17 Number of AST nodes: 17
1
Session s = openSession();
2
		Vetoer v = new Vetoer();
1
Customer cust = new Customer();
3
		v.setStrings( new String[] { "foo", "bar", "baz" } );
2
		
4
		s.save(v); Serializable id = s.save(v);
5
		v.getStrings()[1] = "osama";
6
		s.flush();
7
		s.connection()
3
cust.setCustomerId("xyz123");
4
		cust.setName("Matt");
5
		
6
		Session s = openSession();
7
		Transaction t = s.beginTransaction();
8
		s.persist(cust);
8
.commit();
9
		t.commit();
9
		s.close();
10
		s.close();
10
		
11
		
11
s = openSession();
12
		s = openSession();
12
		v = (Ve
13
		t = s.beginTransaction();
13
toer) s.load(Vetoer.class, id);
14
		List results = s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customer
14
		assertTrue( "serializable type", v.getStrings()[1].equals("osama") );
15
		s.delete(v); s.delete(v);
16
		s.flush();
17
		s.connection()
15
Id='xyz123'").list();
16
		//List results = s.createQuery("from Customer cust left join fetch cust.billingAddress left join fetch cust.shippingAddress").list();
17
		cust = (Customer) results.get(0);
18
		assertNull( cust.getShippingAddress() );
19
		assertNull( cust.getBillingAddress() );
20
		s.delete( cust );
18
.commit();
21
		t.commit();
19
		s.close();
22
		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 comparisons229
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements7
    Number of unmapped statements in the first code fragment10
    Number of unmapped statements in the second code fragment10
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
                                                                    
    1
    Customer cust = new Customer();
                                                                    
    2
    cust.setCustomerId("xyz123");
    Preondition Violations
    Unmatched statement cust.setCustomerId("xyz123"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2
    cust.setCustomerId("xyz123");
    1
    Session s = openSession();
    1
    Session s = openSession();
    4
    Session s = openSession();
    Differences
    Expression1Expression2Difference
    org.hibernate.classic.Sessionorg.hibernate.SessionSUBCLASS_TYPE_MISMATCH
    org.hibernate.classic.Sessionorg.hibernate.SessionSUBCLASS_TYPE_MISMATCH
    4
    Session s = openSession();
    2
    Vetoer v = new Vetoer();
                                                      
                                                    
    3
    cust.setName("Matt");
    Preondition Violations
    Unmatched statement cust.setName("Matt"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3
    cust.setName("Matt");
    3
    v.setStrings(new String[] {"foo", "bar", "baz"});
    3
    v.setStrings(new String[] {"foo", "bar", "baz"});
    Preondition Violations
    Unmatched statement v.setStrings(new String[]{"foo","bar","baz"}); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                      
    4
    s.save(v);
    4
    s.save(v);
    Preondition Violations
    Unmatched statement s.save(v); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                              
                                                                                
    5
    Transaction t = s.beginTransaction();
    Preondition Violations
    Unmatched statement Transaction t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5
    Transaction t = s.beginTransaction();
    5
    Serializable id = s.save(v);
    5
    Serializable id = s.save(v);
    Preondition Violations
    Unmatched statement Serializable id=s.save(v); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                              
    6
    v.getStrings()[1] = "osama";
                                                              
    7
    s.flush();
    7
    s.flush();
    6
    s.persist(cust);
    Differences
    Expression1Expression2Difference
    flushpersistMETHOD_INVOCATION_NAME_MISMATCH
    org.hibernate.classic.Sessionorg.hibernate.SessionSUBCLASS_TYPE_MISMATCH
    s.flush()s.persist(cust)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.persist(cust) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.flush() is a void method call, and thus it cannot be parameterized
    Expression s.persist(cust) is a void method call, and thus it cannot be parameterized
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.persist(cust) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.flush() is a void method call, and thus it cannot be parameterized
    Expression s.persist(cust) is a void method call, and thus it cannot be parameterized
    6
    s.persist(cust);
                                
    7
    t.commit();
    Preondition Violations
    Unmatched statement t.commit(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    7
    t.commit();
    8
    s.connection().commit();
    8
    s.connection().commit();
    Preondition Violations
    Unmatched statement s.connection().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                          
    9
    s.close();
    9
    s.close();
    8
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.classic.Sessionorg.hibernate.SessionSUBCLASS_TYPE_MISMATCH
    8
    s.close();
    10
    s = openSession();
    10
    s = openSession();
    9
    s = openSession();
    Differences
    Expression1Expression2Difference
    org.hibernate.classic.Sessionorg.hibernate.SessionSUBCLASS_TYPE_MISMATCH
    9
    s = openSession();
                                                          
    10
    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
    10
    t = s.beginTransaction();
                                                                                                                                                                                                                                                                  
    11
    List results = s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list();
    Preondition Violations
    Unmatched statement List results=s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11
    List results = s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list();
    11
    v = (Vetoer)s.load(Vetoer.class, id);
    11
    v = (Vetoer)s.load(Vetoer.class, id);
    Preondition Violations
    Unmatched statement v=(Vetoer)s.load(Vetoer.class,id); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                
                                                                        
    12
    cust = (Customer)results.get(0);
    Preondition Violations
    Unmatched statement cust=(Customer)results.get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    cust = (Customer)results.get(0);
    12
    assertTrue("serializable type", v.getStrings()[1].equals("osama"));
    12
    assertTrue("serializable type", v.getStrings()[1].equals("osama"));
    13
    assertNull(cust.getShippingAddress());
    Differences
    Expression1Expression2Difference
    assertTrueassertNullMETHOD_INVOCATION_NAME_MISMATCH
    assertTrue("serializable type",v.getStrings()[1].equals("osama"))assertNull(cust.getShippingAddress())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertTrue("serializable type",v.getStrings()[1].equals("osama")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(cust.getShippingAddress()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue("serializable type",v.getStrings()[1].equals("osama")) is a void method call, and thus it cannot be parameterized
    Expression assertNull(cust.getShippingAddress()) is a void method call, and thus it cannot be parameterized
    Expression assertTrue("serializable type",v.getStrings()[1].equals("osama")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(cust.getShippingAddress()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue("serializable type",v.getStrings()[1].equals("osama")) is a void method call, and thus it cannot be parameterized
    Expression assertNull(cust.getShippingAddress()) is a void method call, and thus it cannot be parameterized
    13
    assertNull(cust.getShippingAddress());
    13
    s.delete(v);
    13
    s.delete(v);
    Preondition Violations
    Unmatched statement s.delete(v); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                    
                                                                                      
    14
    assertNull(cust.getBillingAddress());
    14
    s.delete(v);
    14
    s.delete(v);
    15
    s.delete(cust);
    Differences
    Expression1Expression2Difference
    vcustVARIABLE_NAME_MISMATCH
    org.hibernate.test.legacy.Vetoerorg.hibernate.test.typedmanytoone.CustomerVARIABLE_TYPE_MISMATCH
    org.hibernate.classic.Sessionorg.hibernate.SessionSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.legacy.Vetoer of variable v does not match with type org.hibernate.test.typedmanytoone.Customer of variable cust
    • Make classes org.hibernate.test.legacy.Vetoer and org.hibernate.test.typedmanytoone.Customer extend a common superclass
    15
    s.delete(cust);
    15
    s.flush();
    15
    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
                                
                                  
    16
    t.commit();
    Preondition Violations
    Unmatched statement t.commit(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    16
    t.commit();
    16
    s.connection().commit();
    16
    s.connection().commit();
    Preondition Violations
    Unmatched statement s.connection().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                            
    17
    s.close();
    17
    s.close();
    17
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.classic.Sessionorg.hibernate.SessionSUBCLASS_TYPE_MISMATCH
    17
    s.close();
    Precondition Violations (34)
    Row Violation
    1Unmatched statement cust.setCustomerId("xyz123"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement cust.setName("Matt"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement v.setStrings(new String[]{"foo","bar","baz"}); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Unmatched statement s.save(v); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement Transaction t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement Serializable id=s.save(v); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression s.persist(cust) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression s.flush() is a void method call, and thus it cannot be parameterized
    10Expression s.persist(cust) is a void method call, and thus it cannot be parameterized
    11Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression s.persist(cust) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression s.flush() is a void method call, and thus it cannot be parameterized
    14Expression s.persist(cust) is a void method call, and thus it cannot be parameterized
    15Unmatched statement t.commit(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    16Unmatched statement s.connection().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    18Unmatched statement List results=s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19Unmatched statement v=(Vetoer)s.load(Vetoer.class,id); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    20Unmatched statement cust=(Customer)results.get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Expression assertTrue("serializable type",v.getStrings()[1].equals("osama")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression assertNull(cust.getShippingAddress()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23Expression assertTrue("serializable type",v.getStrings()[1].equals("osama")) is a void method call, and thus it cannot be parameterized
    24Expression assertNull(cust.getShippingAddress()) is a void method call, and thus it cannot be parameterized
    25Expression assertTrue("serializable type",v.getStrings()[1].equals("osama")) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    26Expression assertNull(cust.getShippingAddress()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    27Expression assertTrue("serializable type",v.getStrings()[1].equals("osama")) is a void method call, and thus it cannot be parameterized
    28Expression assertNull(cust.getShippingAddress()) is a void method call, and thus it cannot be parameterized
    29Unmatched statement s.delete(v); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    30Type org.hibernate.test.legacy.Vetoer of variable v does not match with type org.hibernate.test.typedmanytoone.Customer of variable cust
    31Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    32Unmatched statement t.commit(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    33Unmatched statement s.connection().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    34Clone fragment #1 returns variable s with type org.hibernate.classic.Session , while Clone fragment #2 returns variable s with type org.hibernate.Session