1 package org.hibernate.test.mixed; 3 4 import junit.framework.Test; 5 import junit.framework.TestSuite; 6 7 import org.hibernate.Hibernate; 8 import org.hibernate.Session; 9 import org.hibernate.Transaction; 10 import org.hibernate.dialect.PostgreSQLDialect; 11 import org.hibernate.test.TestCase; 12 13 16 public class MixedTest extends TestCase { 17 18 public MixedTest(String str) { 19 super(str); 20 } 21 22 public void testMixedInheritance() { 23 Session s = openSession( new DocumentInterceptor() ); 24 Transaction t = s.beginTransaction(); 25 Folder f = new Folder(); 26 f.setName("/"); 27 s.save(f); 28 29 Document d = new Document(); 30 d.setName("Hibernate in Action"); 31 d.setContent( Hibernate.createBlob( "blah blah blah".getBytes() ) ); 32 d.setParent(f); 33 Long did = (Long ) s.save(d); 34 35 SecureDocument d2 = new SecureDocument(); 36 d2.setName("Secret"); 37 d2.setContent( Hibernate.createBlob( "wxyz wxyz".getBytes() ) ); 38 d2.setPermissionBits( (byte) 664 ); 39 d2.setOwner("gavin"); 40 d2.setParent(f); 41 Long d2id = (Long ) s.save(d2); 42 43 t.commit(); 44 s.close(); 45 46 if ( getDialect() instanceof PostgreSQLDialect ) return; 47 48 s = openSession( new DocumentInterceptor() ); 49 t = s.beginTransaction(); 50 Item id = (Item) s.load(Item.class, did); 51 assertEquals( did, id.getId() ); 52 assertEquals( "Hibernate in Action", id.getName() ); 53 assertEquals( "/", id.getParent().getName() ); 54 55 Item id2 = (Item) s.load(Item.class, d2id); 56 assertEquals( d2id, id2.getId() ); 57 assertEquals( "Secret", id2.getName() ); 58 assertEquals( "/", id2.getParent().getName() ); 59 60 id.setName("HiA"); 61 62 d2 = (SecureDocument) s.load(SecureDocument.class, d2id); 63 d2.setOwner("max"); 64 65 s.flush(); 66 67 s.clear(); 68 69 d = (Document) s.load(Document.class, did); 70 assertEquals( did, d.getId() ); 71 assertEquals( "HiA", d.getName() ); 72 assertNotNull( d.getContent() ); 73 assertEquals( "/", d.getParent().getName() ); 74 assertNotNull( d.getCreated() ); 75 assertNotNull( d.getModified() ); 76 77 d2 = (SecureDocument) s.load(SecureDocument.class, d2id); 78 assertEquals( d2id, d2.getId() ); 79 assertEquals( "Secret", d2.getName() ); 80 assertNotNull( d2.getContent() ); 81 assertEquals( "max", d2.getOwner() ); 82 assertEquals( "/", d2.getParent().getName() ); 83 assertEquals( (byte) 664, d2.getPermissionBits() ); 84 assertNotNull( d2.getCreated() ); 85 assertNotNull( d2.getModified() ); 86 87 s.delete(d); 88 s.delete(d2); 89 90 t.commit(); 91 s.close(); 92 } 93 94 95 protected String [] getMappings() { 96 return new String [] { "mixed/Item.hbm.xml" }; 97 } 98 99 public static Test suite() { 100 return new TestSuite(MixedTest.class); 101 } 102 103 public String getCacheConcurrencyStrategy() { 104 return null; 105 } 106 } 107 108 | Popular Tags |