Example usage for org.hibernate.cfg Configuration Configuration

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

Introduction

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

Prototype

public Configuration() 

Source Link

Usage

From source file:bazydanych.CRUDTest.java

@BeforeClass
public static void setUpConnections() {
    System.out.println("Przygotowanie polaczen");
    try {//from   ww w. j a  v  a2  s.com
        Class.forName(JDBC_DRIVER).newInstance();
        testConnection = DriverManager.getConnection(DB_URL, USER, PASS);
        testStatement = testConnection.createStatement();

        try {
            factory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            System.err.println("Niedane polaczenie za pomoca HIBERNATE : " + ex);
            fail();
        }

    } catch (SQLException | ClassNotFoundException | InstantiationException | IllegalAccessException se) {
        se.printStackTrace();
        fail();
    }
}

From source file:bazydanych.ManageEmployee.java

public static void main(String[] args) {
    try {/*  ww w.  ja  va 2s.com*/
        factory = new Configuration().configure().buildSessionFactory();
    } catch (Throwable ex) {
        System.err.println("Failed to create sessionFactory object." + ex);
        throw new ExceptionInInitializerError(ex);
    }
    ManageEmployee ME = new ManageEmployee();
    /* Let us have a set of certificates for the first employee  */
    HashSet set1 = new HashSet();
    set1.add(new Certificate("MCA"));
    set1.add(new Certificate("MBA"));
    set1.add(new Certificate("PMP"));

    /* Add employee records in the database */
    Integer empID1 = ME.addEmployee("Manoj", "Kumar", 4000, set1);

    /* Another set of certificates for the second employee  */
    HashSet set2 = new HashSet();
    set2.add(new Certificate("BCA"));
    set2.add(new Certificate("BA"));

    /* Add another employee record in the database */
    Integer empID2 = ME.addEmployee("Dilip", "Kumar", 3000, set2);

    /* List down all the employees */
    ME.listEmployees();

    /* Update employee's salary records */
    ME.updateEmployee(empID1, 5000);

    /* Delete an employee from the database */
    ME.deleteEmployee(empID2);

    /* List down all the employees */
    ME.listEmployees();

    System.exit(0);
}

From source file:bd.ac.seu.hibernate.SessionFactorySingleton.java

private SessionFactorySingleton() {
    factory = new Configuration().configure().buildSessionFactory();
}

From source file:bd.ac.seu.labexam.SessionFactorySingleton.java

private SessionFactorySingleton() {
    Configuration configuration = new Configuration();
    configuration.configure();//from  ww  w. j av  a2  s  . c o m
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
            .applySettings(configuration.getProperties()).build();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}

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:bd2.Test.Main.java

private static void setUp() {
    cfg = new Configuration().configure("hibernate.cfg.xml");
    sf = cfg.buildSessionFactory();/*from   w  ww .j  a v a 2  s.  co  m*/

    setUpLicense();
    setUpDriver();
    setUpPassengers();
    setUpTrip();

}

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...)
 *//*from   w  w w  . ja v  a  2  s  .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:be.ugent.tiwi.sleroux.newsrec.newsreclib.dao.mysqlImpl.HibernateDaoTemplate.java

License:Apache License

public HibernateDaoTemplate() {
    if (sessionfactory == null) {
        sessionfactory = new Configuration().configure().buildSessionFactory();
    }
}

From source file:be.ugent.tiwi.sleroux.newsrec.stormNewsFetch.dao.mysqlImpl.HibernateDaoTemplate.java

License:Apache License

/**
 *
 */// w  ww.j a  va 2 s .c  o m
public HibernateDaoTemplate() {
    if (sessionfactory == null) {
        sessionfactory = new Configuration().configure().buildSessionFactory();
    }
}

From source file:beans.Driver.java

public static void main(String[] args) {
    Student s = new Student();
    s.setId(4);/* w  w w . j a  v a  2  s.  c o m*/
    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();
    }
}