1 | public void testQuerySubclassAttribute() {↵ | | 1 | public void testQuerySubclassAttribute() {↵
|
2 | Session s = openSession();↵ | | 2 | Session s = openSession();↵
|
3 | Transaction t = s.beginTransaction();↵ | | 3 | Transaction t = s.beginTransaction();↵
|
4 | Person p = new Person();↵ | | 4 | Person p = new Person();↵
|
5 | p.setName("Emmanuel");↵ | | 5 | p.setName("Emmanuel");↵
|
6 | p.setSex('M');↵ | | 6 | p.setSex('M');↵
|
7 | s.persist(p);↵ | | 7 | s.persist(p);↵
|
8 | Employee q = new Employee();↵ | | 8 | Employee q = new Employee();↵
|
9 | q.setName("Steve");↵ | | 9 | q.setName("Steve");↵
|
10 | q.setSex('M');↵ | | 10 | q.setSex('M');↵
|
11 | q.setTitle("Mr");↵ | | 11 | q.setTitle("Mr");↵
|
12 | q.setSalary( new BigDecimal(1000) );↵ | | 12 | q.setSalary( new BigDecimal(1000) );↵
|
13 | s.persist(q);↵ | | 13 | s.persist(q);↵
|
|
14 | List result = s.createQuery("from Person where salary > 100").list();↵ | | 14 | List result = s.createQuery("from Person where salary > 100").list();↵
|
15 | assertEquals( result.size(), 1 );↵ | | 15 | assertEquals( result.size(), 1 );↵
|
16 | assertSame( result.get(0), q );↵ | | 16 | assertSame( result.get(0), q );↵
|
|
17 | result = s.createQuery("from Person where salary > 100 or name like 'E%'").list();↵ | | 17 | result = s.createQuery("from Person where salary > 100 or name like 'E%'").list();↵
|
18 | assertEquals( result.size(), 2 );↵ | | 18 | assertEquals( result.size(), 2 );↵
|
|
19 | result = s.createCriteria(Person.class)↵ | | 19 | result = s.createCriteria(Person.class)↵
|
20 | .add( Property.forName("salary").gt( new BigDecimal(100) ) )↵ | | 20 | .add( Property.forName("salary").gt( new BigDecimal(100) ) )↵
|
21 | .list();↵ | | 21 | .list();↵
|
22 | assertEquals( result.size(), 1 );↵ | | 22 | assertEquals( result.size(), 1 );↵
|
23 | assertSame( result.get(0), q );↵ | | 23 | assertSame( result.get(0), q );↵
|
|
24 | //TODO: make this work:↵ | | 24 | //TODO: make this work:↵
|
25 | /*result = s.createQuery("select salary from Person where salary > 100").list();↵ | | 25 | /*result = s.createQuery("select salary from Person where salary > 100").list();↵
|
26 | assertEquals( result.size(), 1 );↵ | | 26 | assertEquals( result.size(), 1 );↵
|
27 | assertEquals( result.get(0), new BigDecimal(1000) );*/↵ | | 27 | assertEquals( result.get(0), new BigDecimal(1000) );*/↵
|
|
28 | s.delete(p);↵ | | 28 | s.delete(p);↵
|
29 | s.delete(q);↵ | | 29 | s.delete(q);↵
|
30 | t.commit();↵ | | 30 | t.commit();↵
|
31 | s.close();↵ | | 31 | s.close();↵
|
32 | | | 32 |
|