1 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 ; 10 11 15 public class TablePerClassTest extends TestCase { 16 public void testUnionSubClass() throws Exception { 17 Session s; 18 Transaction tx; 19 s = openSession(); 20 tx = s.beginTransaction(); 21 Machine computer = new Machine(); 22 computer.setWeight( new Double (4) ); 23 Robot asimov = new Robot(); 24 asimov.setWeight( new Double (120) ); 25 asimov.setName("Asimov"); 26 T800 terminator = new T800(); 27 terminator.setName("Terminator"); 28 terminator.setWeight( new Double (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 (10) ); 39 List 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 x) { 50 super(x); } 52 53 protected Class [] getMappings() { 54 return new Class [] { 55 Robot.class, 56 T800.class, 57 Machine.class 58 }; 59 } 60 } 61 | Popular Tags |