1 package org.hibernate.test.annotations.inheritance.union; 3 4 import java.util.List ; 5 6 import org.hibernate.Session; 7 import org.hibernate.Transaction; 8 import org.hibernate.test.annotations.TestCase; 9 10 13 public class SubclassTest extends TestCase { 14 15 public SubclassTest(String x) { 16 super(x); 17 } 18 19 public void testDefault() throws Exception { 20 Session s; 21 Transaction tx; 22 s = openSession(); 23 tx = s.beginTransaction(); 24 File doc = new Document("Enron Stuff To Shred", 1000); 25 Folder folder = new Folder("Enron"); 26 s.persist(doc); 27 s.persist(folder); 28 tx.commit(); 29 s.close(); 30 31 s = openSession(); 32 tx = s.beginTransaction(); 33 List result = s.createCriteria(File.class).list(); 34 assertNotNull(result); 35 assertEquals( 2, result.size() ); 36 File f2 = (File) result.get(0); 37 checkClassType(f2, doc, folder); 38 f2 = (File) result.get(1); 39 checkClassType(f2, doc, folder); 40 tx.commit(); 41 s.close(); 42 } 43 44 private void checkClassType(File fruitToTest, File f, Folder a) { 45 if ( fruitToTest.getName().equals( f.getName() ) ) { 46 assertFalse(fruitToTest instanceof Folder); 47 } else if ( fruitToTest.getName().equals( a.getName() ) ) { 48 assertTrue(fruitToTest instanceof Folder); 49 } else { 50 fail("Result does not contains the previously inserted elements"); 51 } 52 } 53 54 57 protected Class [] getMappings() { 58 return new Class [] { 59 File.class, 60 Folder.class, 61 Document.class, 62 SymbolicLink.class 63 }; 64 } 65 66 } 67 | Popular Tags |