1 package org.hibernate.test.annotations; 3 4 import org.hibernate.MappingException; 5 import org.hibernate.Query; 6 import org.hibernate.Session; 7 import org.hibernate.SessionFactory; 8 import org.hibernate.Transaction; 9 import org.hibernate.cfg.AnnotationConfiguration; 10 import org.hibernate.cfg.Configuration; 11 import org.hibernate.cfg.Environment; 12 13 16 public class ConfigurationTest extends junit.framework.TestCase { 17 public void testDeclarativeMix() throws Exception { 18 AnnotationConfiguration cfg = new AnnotationConfiguration(); 19 cfg.configure("org/hibernate/test/annotations/hibernate.cfg.xml"); 20 cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop"); 21 SessionFactory sf = cfg.buildSessionFactory(); 22 assertNotNull(sf); 23 Session s = sf.openSession(); 24 Transaction tx = s.beginTransaction(); 25 Query q = s.createQuery("from Boat"); 26 assertEquals(0, q.list().size()); 27 q = s.createQuery("from Plane"); 28 assertEquals(0, q.list().size()); 29 tx.commit(); 30 s.close(); 31 sf.close(); 32 } 33 34 public void testDeclarativeAnnWoAnnConfig() throws Exception { 35 Configuration cfg = new Configuration (); 36 try { 37 cfg.configure("org/hibernate/test/annotations/hibernate.cfg.xml"); 38 fail("Configuration object should fail when finding annotated elements declarations"); 39 } catch (MappingException e) { 40 } 42 } 43 } 44 | Popular Tags |