Example usage for org.hibernate.cfg Configuration configure

List of usage examples for org.hibernate.cfg Configuration configure

Introduction

In this page you can find the example usage for org.hibernate.cfg Configuration configure.

Prototype

@Deprecated
public Configuration configure(org.w3c.dom.Document document) throws HibernateException 

Source Link

Usage

From source file:batch.processing.usage.util.HibernateUtil.java

private static SessionFactory buildSessionFactory() {
    try {/* w w  w. j av  a2 s  .co m*/
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();
        return configuration.buildSessionFactory(serviceRegistry);
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:bd2.Test.Main.java

protected static Session getSession() {
    Configuration cfg = new Configuration();
    cfg.configure("hibernate.cfg.xml");
    SessionFactory factory = cfg.buildSessionFactory();
    Session session = factory.openSession();
    return session;
}

From source file:be.shad.tsqb.test.TypeSafeQueryTest.java

License:Apache License

/**
 * Initialize the sessionFactory and helper once.
 * The helper has an override to generate shorter entity names
 * for readability (and it also works in hibernate...)
 *///w  w w . java2s.  c o m
@BeforeClass
public static void initializeClass() {
    if (sessionFactory == null) {
        Configuration config = new Configuration();
        config.configure("be/shad/tsqb/tests/hibernate.cfg.xml");
        sessionFactory = config.buildSessionFactory();
        helper = new TypeSafeQueryHelperImpl(sessionFactory) {
            // trim package for readability:
            @Override
            public String getEntityName(Class<?> entityClass) {
                String entityName = super.getEntityName(entityClass);
                return entityName.substring(entityName.lastIndexOf(".") + 1);
            }
        };
        typeSafeQueryDao = new TypeSafeQueryDaoImpl(sessionFactory, helper);
    }
}

From source file:beans.Driver.java

public static void main(String[] args) {
    Student s = new Student();
    s.setId(4);/*from  ww  w  .  ja v  a2  s.c om*/
    s.setName("Amjad");

    try {

        Configuration cf = new Configuration();
        cf.configure("xml/hibernate.cfg.xml");
        SessionFactory sf = cf.buildSessionFactory();
        Session ses = sf.openSession();

        ses.save(s);
        ses.beginTransaction().commit();
        ses.evict(s);

        ses.close();
        //                
        // ses = sf.openSession();

        // s = (Student)ses.get(Student.class, 1);
        // System.out.println("Name="+s.getName());
        //                System.out.println("Id="+s.getId());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:br.com.cssistemas.dados.HibernateUtil.java

private static SessionFactory buildSessionFactory() {
    try {//  w ww  .j  a v  a2  s.  c  o m
        Configuration cfg = new Configuration();
        cfg.configure("hibernate.cfg.xml");
        return cfg.buildSessionFactory();
    } catch (HibernateException erro) {
        System.out.println("A criao inicial do SessionFactory Falhou. Erro" + erro);
        throw new ExceptionInInitializerError(erro);
    }

}

From source file:br.com.hslife.catu.db.GerarTabelas.java

License:Open Source License

public static void geraTabelas() {
    Configuration cfg = new AnnotationConfiguration();
    cfg.configure("br/com/hslife/catu/db/hibernate.cfg.xml");

    SchemaExport se = new SchemaExport(cfg);
    se.create(true, true);//  w ww .  j av  a  2s. c  o m
}

From source file:br.com.hslife.clickafacil.hibernate.GeraSQL.java

License:Open Source License

public static void main(String args[]) {
    Configuration cfg = new AnnotationConfiguration();
    cfg.configure("br/com/hslife/clickafacil/config/hibernate.cfg.xml");
    SchemaExport se = new SchemaExport(cfg);
    se.create(true, true);/* ww  w  .ja v a  2  s .  co m*/
}

From source file:br.com.hslife.imobiliaria.db.GerarTabelas.java

License:Open Source License

public static void geraTabelas() {
    Configuration cfg = new AnnotationConfiguration();
    cfg.configure("br/com/hslife/imobiliaria/db/hibernate.cfg.xml");

    SchemaExport se = new SchemaExport(cfg);
    se.create(true, true);/*from   ww  w.ja  v  a  2  s . c  om*/
}

From source file:br.com.hslife.sirce.hibernate.GerarTabelas.java

License:Open Source License

public static void geraTabelas() {
    Configuration cfg = new AnnotationConfiguration();
    cfg.configure("br/com/hslife/sirce/hibernate/hibernate.cfg.xml");

    SchemaExport se = new SchemaExport(cfg);
    se.create(true, true);//from   w  ww  .j  a  v a2s.c o  m
}

From source file:br.com.loja.framework.hibernate.HibernateUtil.java

private static SessionFactory buildSessionFactory() {
    try {//w  ww. j ava2  s  . c o  m
        // Create the SessionFactory from hibernate.cfg.xml
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        return configuration.buildSessionFactory();

    } catch (Exception ex) {
        // Make sure you log the exception, as it might be swallowed
        throw new RuntimeException("Falhar ao iniciar configuracao de acesso ao banco de dados", ex);
    }
}