Package org.hibernate.cfg

Examples of org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory()


    try {
      AnnotationConfiguration config = new AnnotationConfiguration();
      config.addAnnotatedClass(Bunny.class);
      config.addAnnotatedClass(PointyTooth.class);
      config.addAnnotatedClass(TwinkleToes.class);
      config.buildSessionFactory();
      String[] schema = config
          .generateSchemaCreationScript(new SQLServerDialect());
      for (String s : schema) {
        log.debug(s);
      }
View Full Code Here


            props.load(is);   
        } finally {
            is.close();
        }       
        cfg.setProperties(props);
        sessionFactory = cfg.buildSessionFactory();
    }

    @AfterClass
    public static void tearDownClass() {
        if (sessionFactory != null) {
View Full Code Here

        if (hibernateInterceptor != null) {
            cfg.setInterceptor(hibernateInterceptor);
        }

        sessionFactory = cfg.buildSessionFactory();
       
    }
   
    @Override
    public SessionFactory getSessionFactory() {
View Full Code Here

public class ConfigurationTest extends junit.framework.TestCase {
  public void testDeclarativeMix() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull( sf );
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();
    Query q = s.createQuery( "from Boat" );
    assertEquals( 0, q.list().size() );
View Full Code Here

  public void testIgnoringHbm() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    cfg.setProperty( AnnotationConfiguration.ARTEFACT, "class, whatever" );
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull( sf );
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();
    Query q;
    try {
View Full Code Here

  public void testPrecedenceHbm() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    cfg.addAnnotatedClass( Boat.class );
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull( sf );
    Session s = sf.openSession();
    s.getTransaction().begin();
    Boat boat = new Boat();
    boat.setSize( 12 );
View Full Code Here

    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    cfg.setProperty( AnnotationConfiguration.ARTEFACT, "class, hbm" );
    cfg.addAnnotatedClass( Boat.class );
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull( sf );
    Session s = sf.openSession();
    s.getTransaction().begin();
    Boat boat = new Boat();
    boat.setSize( 12 );
View Full Code Here

  public void testHbmWithSubclassExtends() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    cfg.addClass( Ferry.class );
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull( sf );
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();
    Query q = s.createQuery( "from Ferry" );
    assertEquals( 0, q.list().size() );
View Full Code Here

  public void testAnnReferencesHbm() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    cfg.addAnnotatedClass( Port.class );
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull( sf );
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();
    Query q = s.createQuery( "from Boat" );
    assertEquals( 0, q.list().size() );
View Full Code Here

    p.put( "hibernate.show_sql", "true" );
    ac.setProperties( p );
    ac.addAnnotatedClass( Plane.class );
    SessionFactory sf;
    try {
      sf = ac.buildSessionFactory();
      fail( "Driver property overriding should work" );
      sf.close();
    }
    catch (HibernateException he) {
      //success
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.