Package org.hibernate

Examples of org.hibernate.SessionFactory.openSession()


    stats.setStatisticsEnabled(true);
    Session s = sf.openSession();
    assertEquals( 1, stats.getSessionOpenCount() );
    s.close();
    assertEquals( 1, stats.getSessionCloseCount() );
    s = sf.openSession();
    Transaction tx = s.beginTransaction();
    A a = new A();
    a.setName("mya");
    s.save(a);
    a.setName("b");
View Full Code Here


    s.save(a);
    a.setName("b");
    tx.commit();
    s.close();
    assertEquals( 1, stats.getFlushCount() );
    s = sf.openSession();
    tx = s.beginTransaction();
    String hql = "from " + A.class.getName();
    Query q = s.createQuery(hql);
    q.list();
    tx.commit();
View Full Code Here

    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() );
    q = s.createQuery( "from Plane" );
    assertEquals( 0, q.list().size() );
View Full Code Here

    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "class" );
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull( sf );
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();
    Query q;
    try {
      s.createQuery( "from Boat" ).list();
      fail( "Boat should not be mapped" );
View Full Code Here

    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 );
    boat.setWeight( 34 );
    s.persist( boat );
View Full Code Here

    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "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 );
    boat.setWeight( 34 );
    s.persist( boat );
View Full Code Here

    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() );
    q = s.createQuery( "from Plane" );
    assertEquals( 0, q.list().size() );
View Full Code Here

    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() );
    q = s.createQuery( "from Port" );
    assertEquals( 0, q.list().size() );
View Full Code Here

    coll.setLazy(false);
    SessionFactory sf = getCfg().buildSessionFactory();
    stats = sf.getStatistics();
    stats.clear();
    stats.setStatisticsEnabled(true);
    s = sf.openSession();
    tx = s.beginTransaction();
    europe = fillDb(s);
    tx.commit();
    s.clear();
    tx = s.beginTransaction();
View Full Code Here

    coll.setLazy(false);
    sf = getCfg().buildSessionFactory();
    stats = sf.getStatistics();
    stats.clear();
    stats.setStatisticsEnabled(true);
    s = sf.openSession();
    tx = s.beginTransaction();
    europe = fillDb(s);
    tx.commit();
    s.clear();
    tx = s.beginTransaction();
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.