KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > annotations > tableperclass > TablePerClassTest


1 //$Id: TablePerClassTest.java,v 1.1 2005/05/12 13:33:51 epbernard Exp $
2
package org.hibernate.test.annotations.tableperclass;
3
4 import org.hibernate.test.annotations.TestCase;
5 import org.hibernate.Session;
6 import org.hibernate.Transaction;
7 import org.hibernate.Query;
8
9 import java.util.List JavaDoc;
10
11 /**
12  *
13  * @author Emmanuel Bernard
14  */

15 public class TablePerClassTest extends TestCase {
16     public void testUnionSubClass() throws Exception JavaDoc {
17         Session s;
18         Transaction tx;
19         s = openSession();
20         tx = s.beginTransaction();
21         Machine computer = new Machine();
22         computer.setWeight( new Double JavaDoc(4) );
23         Robot asimov = new Robot();
24         asimov.setWeight( new Double JavaDoc(120) );
25         asimov.setName("Asimov");
26         T800 terminator = new T800();
27         terminator.setName("Terminator");
28         terminator.setWeight( new Double JavaDoc(300) );
29         terminator.setTargetName("Sarah Connor");
30         s.persist(computer);
31         s.persist(asimov);
32         s.persist(terminator);
33         tx.commit();
34         s.close();
35         s = openSession();
36         tx = s.beginTransaction();
37         Query q = s.createQuery("from Machine m where m.weight >= :weight");
38         q.setDouble("weight", new Double JavaDoc(10) );
39         List JavaDoc result = q.list();
40         assertEquals( 2, result.size() );
41         tx.commit();
42         s.close();
43         s = openSession();
44         tx = s.beginTransaction();
45         tx.commit();
46         s.close();
47     }
48
49     public TablePerClassTest(String JavaDoc x) {
50         super(x); //To change body of overridden methods use File | Settings | File Templates.
51
}
52
53     protected Class JavaDoc[] getMappings() {
54         return new Class JavaDoc[] {
55             Robot.class,
56             T800.class,
57             Machine.class
58         };
59     }
60 }
61
Popular Tags