File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/discriminator/DiscriminatorTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java | |||
Method name: void testQuerySubclassAttribute()
|
Method name: void testQuerySubclassAttribute()
|
|||
Number of AST nodes: 24 | Number of AST nodes: 24 | |||
1 | Session s = openSession();↵ | 1 | Session s = openSession();↵ | |
2 | Transaction t = s.beginTransaction();↵ | 2 | Transaction t = s.beginTransaction();↵ | |
3 | Person p = new Person();↵ | 3 | Person p = new Person();↵ | |
4 | p.setName("Emmanuel");↵ | 4 | p.setName("Emmanuel");↵ | |
5 | p.setSex('M');↵ | 5 | p.setSex('M');↵ | |
6 | s.persist(p);↵ | 6 | s.persist(p);↵ | |
7 | Employee q = new Employee();↵ | 7 | Employee q = new Employee();↵ | |
8 | q.setName("Steve");↵ | 8 | q.setName("Steve");↵ | |
9 | q.setSex('M');↵ | 9 | q.setSex('M');↵ | |
10 | q.setTitle("Mr");↵ | 10 | q.setTitle("Mr");↵ | |
11 | q.setSalary( new BigDecimal(1000) );↵ | 11 | q.setSalary( new BigDecimal(1000) );↵ | |
12 | s.persist(q);↵ | 12 | s.persist(q);↵ | |
13 | List result = s.createQuery("from Person where salary > 100").list();↵ | 13 | List result = s.createQuery("from Person where salary > 100").list();↵ | |
14 | assertEquals( result.size(), 1 );↵ | 14 | assertEquals( result.size(), 1 );↵ | |
15 | assertSame( result.get(0), q );↵ | 15 | assertSame( result.get(0), q );↵ | |
16 | result = s.createQuery("from Person where salary > 100 or name like 'E%'").list();↵ | 16 | result = s.createQuery("from Person where salary > 100 or name like 'E%'").list();↵ | |
17 | assertEquals( result.size(), 2 );↵ | 17 | assertEquals( result.size(), 2 );↵ | |
18 | result = s.createCriteria(Person.class)↵ | 18 | result = s.createCriteria(Person.class)↵ | |
19 | .add( Property.forName("salary").gt( new BigDecimal(100) ) )↵ | 19 | .add( Property.forName("salary").gt( new BigDecimal(100) ) )↵ | |
20 | .list();↵ | 20 | .list();↵ | |
21 | assertEquals( result.size(), 1 );↵ | 21 | assertEquals( result.size(), 1 );↵ | |
22 | assertSame( result.get(0), q );↵ | 22 | assertSame( result.get(0), q );↵ | |
23 | //TODO: make this work:↵ | 23 | //TODO: make this work:↵ | |
24 | /*result = s.createQuery("select salary from Person where salary > 100").list();↵ | 24 | /*result = s.createQuery("select salary from Person where salary > 100").list();↵ | |
25 | assertEquals( result.size(), 1 );↵ | 25 | assertEquals( result.size(), 1 );↵ | |
26 | assertEquals( result.get(0), new BigDecimal(1000) );*/↵ | 26 | assertEquals( result.get(0), new BigDecimal(1000) );*/↵ | |
27 | s.delete(p);↵ | 27 | s.delete(p);↵ | |
28 | s.delete(q);↵ | 28 | s.delete(q);↵ | |
29 | t.commit();↵ | 29 | t.commit();↵ | |
30 | s.close(); | 30 |
| |
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) | 0.0 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 218 |
Number of mapped statements | 22 |
Number of unmapped statements in the first code fragment | 2 |
Number of unmapped statements in the second code fragment | 2 |
Time elapsed for statement mapping (ms) | 0.0 |
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 | Person p = new Person(); | |||||||||||||
3 | Person p = new Person(); | | |||||||||||||
4 | p.setName("Emmanuel"); |
| 4 | p.setName("Emmanuel"); | |||||||||||
5 | p.setSex('M'); |
| 5 | p.setSex('M'); | |||||||||||
6 | s.persist(p); |
| 6 | s.persist(p); | |||||||||||
| 7 | Employee q = new Employee(); | |||||||||||||
7 | Employee q = new Employee(); | | |||||||||||||
8 | q.setName("Steve"); |
| 8 | q.setName("Steve"); | |||||||||||
9 | q.setSex('M'); |
| 9 | q.setSex('M'); | |||||||||||
10 | q.setTitle("Mr"); |
| 10 | q.setTitle("Mr"); | |||||||||||
11 | q.setSalary(new BigDecimal(1000)); |
| 11 | q.setSalary(new BigDecimal(1000)); | |||||||||||
12 | s.persist(q); |
| 12 | s.persist(q); | |||||||||||
13 | List result = s.createQuery("from Person where salary > 100").list(); | 13 | List result = s.createQuery("from Person where salary > 100").list(); | ||||||||||||
14 | assertEquals(result.size(), 1); | 14 | assertEquals(result.size(), 1); | ||||||||||||
15 | assertSame(result.get(0), q); |
| 15 | assertSame(result.get(0), q); | |||||||||||
16 | result = s.createQuery("from Person where salary > 100 or name like 'E%'").list(); | 16 | result = s.createQuery("from Person where salary > 100 or name like 'E%'").list(); | ||||||||||||
17 | assertEquals(result.size(), 2); | 17 | assertEquals(result.size(), 2); | ||||||||||||
18 | result = s.createCriteria(Person.class).add(Property.forName("salary").gt(new BigDecimal(100))).list(); |
| 18 | result = s.createCriteria(Person.class).add(Property.forName("salary").gt(new BigDecimal(100))).list(); | |||||||||||
19 | assertEquals(result.size(), 1); | 19 | assertEquals(result.size(), 1); | ||||||||||||
20 | assertSame(result.get(0), q); |
| 20 | assertSame(result.get(0), q); | |||||||||||
21 | s.delete(p); |
| 21 | s.delete(p); | |||||||||||
22 | s.delete(q); |
| 22 | s.delete(q); | |||||||||||
23 | t.commit(); | 23 | t.commit(); | ||||||||||||
24 | s.close(); | 24 | s.close(); |
Row | Violation |
---|---|
1 | Type org.hibernate.test.discriminator.Person of variable p does not match with type org.hibernate.test.joinedsubclass.Person of variable p |
2 | Type org.hibernate.test.discriminator.Person of variable p does not match with type org.hibernate.test.joinedsubclass.Person of variable p |
3 | Type org.hibernate.test.discriminator.Person of variable p does not match with type org.hibernate.test.joinedsubclass.Person of variable p |
4 | Type org.hibernate.test.discriminator.Employee of variable q does not match with type org.hibernate.test.joinedsubclass.Employee of variable q |
5 | Type org.hibernate.test.discriminator.Employee of variable q does not match with type org.hibernate.test.joinedsubclass.Employee of variable q |
6 | Type org.hibernate.test.discriminator.Employee of variable q does not match with type org.hibernate.test.joinedsubclass.Employee of variable q |
7 | Type org.hibernate.test.discriminator.Employee of variable q does not match with type org.hibernate.test.joinedsubclass.Employee of variable q |
8 | Type org.hibernate.test.discriminator.Employee of variable q does not match with type org.hibernate.test.joinedsubclass.Employee of variable q |
9 | Type org.hibernate.test.discriminator.Employee of variable q does not match with type org.hibernate.test.joinedsubclass.Employee of variable q |
10 | Type org.hibernate.test.discriminator.Employee of variable q does not match with type org.hibernate.test.joinedsubclass.Employee of variable q |
11 | Type org.hibernate.test.discriminator.Person of variable p does not match with type org.hibernate.test.joinedsubclass.Person of variable p |
12 | Type org.hibernate.test.discriminator.Employee of variable q does not match with type org.hibernate.test.joinedsubclass.Employee of variable q |