File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/unionsubclass2/UnionSubclassTest.java | |||
Method name: void testJoinedSubclass()
|
Method name: void testUnionSubclass()
|
|||
Number of AST nodes: 54 | Number of AST nodes: 54 | |||
1 | Session s = openSession();↵ | 1 | Session s = openSession();↵ | |
2 | Transaction t = s.beginTransaction();↵ | 2 | Transaction t = s.beginTransaction();↵ | |
3 | ↵ | |||
3 | Employee mark = new Employee();↵ | 4 | Employee mark = new Employee();↵ | |
4 | mark.setName("Mark");↵ | 5 | mark.setName("Mark");↵ | |
5 | mark.setTitle("internal sales");↵ | 6 | mark.setTitle("internal sales");↵ | |
6 | mark.setSex('M');↵ | 7 | mark.setSex('M');↵ | |
7 | mark.setAddress("buckhead");↵ | 8 | mark.setAddress("buckhead");↵ | |
8 | mark.setZip("30305");↵ | 9 | mark.setZip("30305");↵ | |
9 | mark.setCountry("USA");↵ | 10 | mark.setCountry("USA");↵ | |
11 | ↵ | |||
10 | Customer joe = new Customer();↵ | 12 | Customer joe = new Customer();↵ | |
11 | joe.setName("Joe");↵ | 13 | joe.setName("Joe");↵ | |
12 | joe.setAddress("San Francisco");↵ | 14 | joe.setAddress("San Francisco");↵ | |
13 | joe.setZip("XXXXX");↵ | 15 | joe.setZip("XXXXX");↵ | |
14 | joe.setCountry("USA");↵ | 16 | joe.setCountry("USA");↵ | |
15 | joe.setComments("Very demanding");↵ | 17 | joe.setComments("Very demanding");↵ | |
16 | joe.setSex('M');↵ | 18 | joe.setSex('M');↵ | |
17 | joe.setSalesperson(mark);↵ | 19 | joe.setSalesperson(mark);↵ | |
20 | ↵ | |||
18 | Person yomomma = new Person();↵ | 21 | Person yomomma = new Person();↵ | |
19 | yomomma.setName("mum");↵ | 22 | yomomma.setName("mum");↵ | |
20 | yomomma.setSex('F');↵ | 23 | yomomma.setSex('F');↵ | |
24 | ↵ | |||
21 | s.save(yomomma);↵ | 25 | s.save(yomomma);↵ | |
22 | s.save(mark);↵ | 26 | s.save(mark);↵ | |
23 | s.save(joe);↵ | 27 | s.save(joe);↵ | |
28 | ↵ | |||
24 | assertEquals( s.createQuery("from java.io.Serializable").list().size(), 0 );↵ | 29 | assertEquals( s.createQuery("from java.io.Serializable").list().size(), 0 );↵ | |
30 | ↵ | |||
25 | assertEquals( s.createQuery("from Person").list().size(), 3 );↵ | 31 | assertEquals( s.createQuery("from Person").list().size(), 3 );↵ | |
26 | assertEquals( s.createQuery("from Person p where p.class = Customer").list().size(), 1 );↵ | 32 | assertEquals( s.createQuery("from Person p where p.class = Customer").list().size(), 1 );↵ | |
27 | assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 );↵ | 33 | assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 );↵ | |
28 | s.clear();↵ | 34 | s.clear();↵ | |
29 | List customers = s.createQuery("from Customer c left join fetch c.salesperson").list();↵ | 35 | List customers = s.createQuery("from Customer c left join fetch c.salesperson").list();↵ | |
30 | for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {↵ | 36 | for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {↵ | |
31 | Customer c = (Customer) iter.next();↵ | 37 | Customer c = (Customer) iter.next();↵ | |
32 | assertTrue( Hibernate.isInitialized( c.getSalesperson() ) );↵ | 38 | assertTrue( Hibernate.isInitialized( c.getSalesperson() ) );↵ | |
33 | assertEquals( c.getSalesperson().getName(), "Mark" );↵ | 39 | assertEquals( c.getSalesperson().getName(), "Mark" );↵ | |
34 | }↵ | 40 | }↵ | |
35 | assertEquals( customers.size(), 1 );↵ | 41 | assertEquals( customers.size(), 1 );↵ | |
36 | s.clear();↵ | 42 | s.clear();↵ | |
43 | ↵ | |||
37 | customers = s.createQuery("from Customer").list();↵ | 44 | customers = s.createQuery("from Customer").list();↵ | |
38 | for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {↵ | 45 | for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {↵ | |
39 | Customer c = (Customer) iter.next();↵ | 46 | Customer c = (Customer) iter.next();↵ | |
40 | assertFalse( Hibernate.isInitialized( c.getSalesperson() ) );↵ | 47 | assertFalse( Hibernate.isInitialized( c.getSalesperson() ) );↵ | |
41 | assertEquals( c.getSalesperson().getName(), "Mark" );↵ | 48 | assertEquals( c.getSalesperson().getName(), "Mark" );↵ | |
42 | }↵ | 49 | }↵ | |
43 | assertEquals( customers.size(), 1 );↵ | 50 | assertEquals( customers.size(), 1 );↵ | |
44 | s.clear();↵ | 51 | s.clear();↵ | |
52 | ↵ | |||
45 | mark = (Employee) s.get( Employee.class, new Long( mark.getId() ) );↵ | 53 | mark = (Employee) s.get( Employee.class, new Long( mark.getId() ) );↵ | |
46 | joe = (Customer) s.get( Customer.class, new Long( joe.getId() ) );↵ | 54 | joe = (Customer) s.get( Customer.class, new Long( joe.getId() ) );↵ | |
55 | ↵ | |||
47 | mark.setZip("30306");↵ | 56 | mark.setZip("30306");↵ | |
48 | assertEquals( s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1 );↵ | 57 | assertEquals( s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1 );↵ | |
49 | if ( supportsRowValueConstructorSyntaxInInList() ) {↵ | 58 | if ( supportsRowValueConstructorSyntaxInInList() ) {↵ | |
50 | s.createCriteria(Person.class).add(↵ | 59 | s.createCriteria(Person.class).add( ↵ | |
51 | Restrictions.in("address", new Address[] { mark.getAddress(), joe.getAddress() } )↵ | 60 | Restrictions.in("address", new Address[] { mark.getAddress(), joe.getAddress() } ) ↵ | |
52 | ).list();↵ | 61 | ).list();↵ | |
53 | }↵ | 62 | }↵ | |
63 | ↵ | |||
54 | s.delete(mark);↵ | 64 | s.delete(mark);↵ | |
55 | s.delete(joe);↵ | 65 | s.delete(joe);↵ | |
56 | s.delete(yomomma);↵ | 66 | s.delete(yomomma);↵ | |
57 | assertTrue( s.createQuery("from Person").list().isEmpty() );↵ | 67 | assertTrue( s.createQuery("from Person").list().isEmpty() );↵ | |
58 | t.commit();↵ | 68 | t.commit();↵ | |
59 | s.close(); | 69 |
| |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 1.5 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 954 |
Number of mapped statements | 46 |
Number of unmapped statements in the first code fragment | 8 |
Number of unmapped statements in the second code fragment | 8 |
Time elapsed for statement mapping (ms) | 151.1 |
Clone type | Type 2 |
ID | Statement | ID | Statement | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Session s = openSession(); | 1 | Session s = openSession(); | ||||||||||||||||||
2 | Transaction t = s.beginTransaction(); | 2 | Transaction t = s.beginTransaction(); | ||||||||||||||||||
| 3 | Employee mark = new Employee(); | |||||||||||||||||||
3 | Employee mark = new Employee(); | | |||||||||||||||||||
4 | mark.setName("Mark"); |
| 4 | mark.setName("Mark"); | |||||||||||||||||
5 | mark.setTitle("internal sales"); |
| 5 | mark.setTitle("internal sales"); | |||||||||||||||||
6 | mark.setSex('M'); |
| 6 | mark.setSex('M'); | |||||||||||||||||
7 | mark.setAddress("buckhead"); |
| 7 | mark.setAddress("buckhead"); | |||||||||||||||||
8 | mark.setZip("30305"); |
| 8 | mark.setZip("30305"); | |||||||||||||||||
9 | mark.setCountry("USA"); |
| 9 | mark.setCountry("USA"); | |||||||||||||||||
| 10 | Customer joe = new Customer(); | |||||||||||||||||||
10 | Customer joe = new Customer(); | | |||||||||||||||||||
11 | joe.setName("Joe"); |
| 11 | joe.setName("Joe"); | |||||||||||||||||
12 | joe.setAddress("San Francisco"); |
| 12 | joe.setAddress("San Francisco"); | |||||||||||||||||
13 | joe.setZip("XXXXX"); |
| 13 | joe.setZip("XXXXX"); | |||||||||||||||||
14 | joe.setCountry("USA"); |
| 14 | joe.setCountry("USA"); | |||||||||||||||||
15 | joe.setComments("Very demanding"); |
| 15 | joe.setComments("Very demanding"); | |||||||||||||||||
16 | joe.setSex('M'); |
| 16 | joe.setSex('M'); | |||||||||||||||||
17 | joe.setSalesperson(mark); |
| 17 | joe.setSalesperson(mark); | |||||||||||||||||
| 18 | Person yomomma = new Person(); | |||||||||||||||||||
18 | Person yomomma = new Person(); | | |||||||||||||||||||
19 | yomomma.setName("mum"); |
| 19 | yomomma.setName("mum"); | |||||||||||||||||
20 | yomomma.setSex('F'); |
| 20 | yomomma.setSex('F'); | |||||||||||||||||
21 | s.save(yomomma); |
| 21 | s.save(yomomma); | |||||||||||||||||
22 | s.save(mark); |
| 22 | s.save(mark); | |||||||||||||||||
23 | s.save(joe); |
| 23 | s.save(joe); | |||||||||||||||||
24 | assertEquals(s.createQuery("from java.io.Serializable").list().size(), 0); | 24 | assertEquals(s.createQuery("from java.io.Serializable").list().size(), 0); | ||||||||||||||||||
25 | assertEquals(s.createQuery("from Person").list().size(), 3); | 25 | assertEquals(s.createQuery("from Person").list().size(), 3); | ||||||||||||||||||
26 | assertEquals(s.createQuery("from Person p where p.class = Customer").list().size(), 1); | 26 | assertEquals(s.createQuery("from Person p where p.class = Customer").list().size(), 1); | ||||||||||||||||||
27 | assertEquals(s.createQuery("from Person p where p.class = Person").list().size(), 1); | 27 | assertEquals(s.createQuery("from Person p where p.class = Person").list().size(), 1); | ||||||||||||||||||
28 | s.clear(); | 28 | s.clear(); | ||||||||||||||||||
29 | List customers = s.createQuery("from Customer c left join fetch c.salesperson").list(); | 29 | List customers = s.createQuery("from Customer c left join fetch c.salesperson").list(); | ||||||||||||||||||
30 | for (Iterator iter = customers.iterator(); iter.hasNext(); ) | 30 | for (Iterator iter = customers.iterator(); iter.hasNext(); ) | ||||||||||||||||||
|
| 31 | Customer c = (Customer)iter.next(); | ||||||||||||||||||
31 | Customer c = (Customer)iter.next(); |
| | ||||||||||||||||||
32 | assertTrue(Hibernate.isInitialized(c.getSalesperson())); |
| 32 | assertTrue(Hibernate.isInitialized(c.getSalesperson())); | |||||||||||||||||
33 | assertEquals(c.getSalesperson().getName(), "Mark"); |
| 33 | assertEquals(c.getSalesperson().getName(), "Mark"); | |||||||||||||||||
34 | assertEquals(customers.size(), 1); | 34 | assertEquals(customers.size(), 1); | ||||||||||||||||||
35 | s.clear(); | 35 | s.clear(); | ||||||||||||||||||
36 | customers = s.createQuery("from Customer").list(); | 36 | customers = s.createQuery("from Customer").list(); | ||||||||||||||||||
37 | for (Iterator iter = customers.iterator(); iter.hasNext(); ) | 37 | for (Iterator iter = customers.iterator(); iter.hasNext(); ) | ||||||||||||||||||
|
| 38 | Customer c = (Customer)iter.next(); | ||||||||||||||||||
38 | Customer c = (Customer)iter.next(); |
| | ||||||||||||||||||
39 | assertFalse(Hibernate.isInitialized(c.getSalesperson())); |
| 39 | assertFalse(Hibernate.isInitialized(c.getSalesperson())); | |||||||||||||||||
40 | assertEquals(c.getSalesperson().getName(), "Mark"); |
| 40 | assertEquals(c.getSalesperson().getName(), "Mark"); | |||||||||||||||||
41 | assertEquals(customers.size(), 1); | 41 | assertEquals(customers.size(), 1); | ||||||||||||||||||
42 | s.clear(); | 42 | s.clear(); | ||||||||||||||||||
|
| 43 | mark = (Employee)s.get(Employee.class, new Long(mark.getId())); | ||||||||||||||||||
43 | mark = (Employee)s.get(Employee.class, new Long(mark.getId())); |
| | ||||||||||||||||||
|
| 44 | joe = (Customer)s.get(Customer.class, new Long(joe.getId())); | ||||||||||||||||||
44 | joe = (Customer)s.get(Customer.class, new Long(joe.getId())); |
| | ||||||||||||||||||
45 | mark.setZip("30306"); |
| 45 | mark.setZip("30306"); | |||||||||||||||||
46 | assertEquals(s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1); | 46 | assertEquals(s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1); | ||||||||||||||||||
47 | if (supportsRowValueConstructorSyntaxInInList()) | 47 | if (supportsRowValueConstructorSyntaxInInList()) | ||||||||||||||||||
|
| 48 | s.createCriteria(Person.class).add(Restrictions.in("address", new Address[] {mark.getAddress(), joe.getAddress()})).list(); | ||||||||||||||||||
48 | s.createCriteria(Person.class).add(Restrictions.in("address", new Address[] {mark.getAddress(), joe.getAddress()})).list(); |
| | ||||||||||||||||||
49 | s.delete(mark); |
| 49 | s.delete(mark); | |||||||||||||||||
50 | s.delete(joe); |
| 50 | s.delete(joe); | |||||||||||||||||
51 | s.delete(yomomma); |
| 51 | s.delete(yomomma); | |||||||||||||||||
52 | assertTrue(s.createQuery("from Person").list().isEmpty()); | 52 | assertTrue(s.createQuery("from Person").list().isEmpty()); | ||||||||||||||||||
53 | t.commit(); | 53 | t.commit(); | ||||||||||||||||||
54 | s.close(); | 54 | s.close(); |
Row | Violation |
---|---|
1 | Type org.hibernate.test.joinedsubclass.Employee of variable mark does not match with type org.hibernate.test.unionsubclass2.Employee of variable mark |
2 | Type org.hibernate.test.joinedsubclass.Employee of variable mark does not match with type org.hibernate.test.unionsubclass2.Employee of variable mark |
3 | Type org.hibernate.test.joinedsubclass.Employee of variable mark does not match with type org.hibernate.test.unionsubclass2.Employee of variable mark |
4 | Type org.hibernate.test.joinedsubclass.Employee of variable mark does not match with type org.hibernate.test.unionsubclass2.Employee of variable mark |
5 | Type org.hibernate.test.joinedsubclass.Employee of variable mark does not match with type org.hibernate.test.unionsubclass2.Employee of variable mark |
6 | Type org.hibernate.test.joinedsubclass.Employee of variable mark does not match with type org.hibernate.test.unionsubclass2.Employee of variable mark |
7 | Type org.hibernate.test.joinedsubclass.Customer of variable joe does not match with type org.hibernate.test.unionsubclass2.Customer of variable joe |
8 | Type org.hibernate.test.joinedsubclass.Customer of variable joe does not match with type org.hibernate.test.unionsubclass2.Customer of variable joe |
9 | Type org.hibernate.test.joinedsubclass.Customer of variable joe does not match with type org.hibernate.test.unionsubclass2.Customer of variable joe |
10 | Type org.hibernate.test.joinedsubclass.Customer of variable joe does not match with type org.hibernate.test.unionsubclass2.Customer of variable joe |
11 | Type org.hibernate.test.joinedsubclass.Customer of variable joe does not match with type org.hibernate.test.unionsubclass2.Customer of variable joe |
12 | Type org.hibernate.test.joinedsubclass.Customer of variable joe does not match with type org.hibernate.test.unionsubclass2.Customer of variable joe |
13 | Type org.hibernate.test.joinedsubclass.Employee of variable mark does not match with type org.hibernate.test.unionsubclass2.Employee of variable mark |
14 | Type org.hibernate.test.joinedsubclass.Customer of variable joe does not match with type org.hibernate.test.unionsubclass2.Customer of variable joe |
15 | Type org.hibernate.test.joinedsubclass.Person of variable yomomma does not match with type org.hibernate.test.unionsubclass2.Person of variable yomomma |
16 | Type org.hibernate.test.joinedsubclass.Person of variable yomomma does not match with type org.hibernate.test.unionsubclass2.Person of variable yomomma |
17 | Type org.hibernate.test.joinedsubclass.Person of variable yomomma does not match with type org.hibernate.test.unionsubclass2.Person of variable yomomma |
18 | Type org.hibernate.test.joinedsubclass.Employee of variable mark does not match with type org.hibernate.test.unionsubclass2.Employee of variable mark |
19 | Type org.hibernate.test.joinedsubclass.Customer of variable joe does not match with type org.hibernate.test.unionsubclass2.Customer of variable joe |
20 | Unmatched statement Customer c=(Customer)iter.next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
21 | Unmatched statement Customer c=(Customer)iter.next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
22 | Expression c.getSalesperson() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
23 | Expression c.getSalesperson() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
24 | Type org.hibernate.test.joinedsubclass.Employee of variable c.getSalesperson() does not match with type org.hibernate.test.unionsubclass2.Employee of variable c.getSalesperson() |
25 | Type org.hibernate.test.joinedsubclass.Customer of variable c does not match with type org.hibernate.test.unionsubclass2.Customer of variable c |
26 | Expression c.getSalesperson() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
27 | Expression c.getSalesperson() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
28 | Type org.hibernate.test.joinedsubclass.Employee of variable c.getSalesperson() does not match with type org.hibernate.test.unionsubclass2.Employee of variable c.getSalesperson() |
29 | Type org.hibernate.test.joinedsubclass.Customer of variable c does not match with type org.hibernate.test.unionsubclass2.Customer of variable c |
30 | Unmatched statement Customer c=(Customer)iter.next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
31 | Unmatched statement Customer c=(Customer)iter.next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
32 | Expression c.getSalesperson() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
33 | Expression c.getSalesperson() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
34 | Type org.hibernate.test.joinedsubclass.Employee of variable c.getSalesperson() does not match with type org.hibernate.test.unionsubclass2.Employee of variable c.getSalesperson() |
35 | Type org.hibernate.test.joinedsubclass.Customer of variable c does not match with type org.hibernate.test.unionsubclass2.Customer of variable c |
36 | Expression c.getSalesperson() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
37 | Expression c.getSalesperson() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
38 | Type org.hibernate.test.joinedsubclass.Employee of variable c.getSalesperson() does not match with type org.hibernate.test.unionsubclass2.Employee of variable c.getSalesperson() |
39 | Type org.hibernate.test.joinedsubclass.Customer of variable c does not match with type org.hibernate.test.unionsubclass2.Customer of variable c |
40 | Unmatched statement mark=(Employee)s.get(Employee.class,new Long(mark.getId())); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
41 | Unmatched statement mark=(Employee)s.get(Employee.class,new Long(mark.getId())); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
42 | Unmatched statement joe=(Customer)s.get(Customer.class,new Long(joe.getId())); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
43 | Unmatched statement joe=(Customer)s.get(Customer.class,new Long(joe.getId())); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
44 | Type org.hibernate.test.joinedsubclass.Employee of variable mark does not match with type org.hibernate.test.unionsubclass2.Employee of variable mark |
45 | Unmatched statement s.createCriteria(Person.class).add(Restrictions.in("address",new Address[]{mark.getAddress(),joe.getAddress()})).list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
46 | Unmatched statement s.createCriteria(Person.class).add(Restrictions.in("address",new Address[]{mark.getAddress(),joe.getAddress()})).list(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
47 | Unmatched statement s.createCriteria(Person.class).add(Restrictions.in("address",new Address[]{mark.getAddress(),joe.getAddress()})).list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
48 | Unmatched statement s.createCriteria(Person.class).add(Restrictions.in("address",new Address[]{mark.getAddress(),joe.getAddress()})).list(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
49 | Type org.hibernate.test.joinedsubclass.Employee of variable mark does not match with type org.hibernate.test.unionsubclass2.Employee of variable mark |
50 | Type org.hibernate.test.joinedsubclass.Customer of variable joe does not match with type org.hibernate.test.unionsubclass2.Customer of variable joe |
51 | Type org.hibernate.test.joinedsubclass.Person of variable yomomma does not match with type org.hibernate.test.unionsubclass2.Person of variable yomomma |