/* * Copyright (c) 2011, StripBandunk and/or its affiliates. All rights reserved. * * http://stripbandunk.com/ * * STRIPBANDUNK PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package com.stripbandunk.formlogin.helper; import com.stripbandunk.formlogin.entity.Pengguna; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.dialect.MySQL5InnoDBDialect; public class HibernateHelper { private final static SessionFactory sessionFactory; static { Configuration configuration = new Configuration(); // konfigurasi connection configuration.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver"); configuration.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/stripbandunk_formlogin"); configuration.setProperty("hibernate.connection.username", "root"); configuration.setProperty("hibernate.connection.password", "root"); // konfigurasi hibernate configuration.setProperty("hibernate.dialect", MySQL5InnoDBDialect.class.getName()); configuration.setProperty("hibernate.hbm2ddl.auto", "update"); // mapping entitas configuration.addAnnotatedClass(Pengguna.class); // membuat session factory sessionFactory = configuration.buildSessionFactory(); // pastikan di-close saat aplikasi ditutup HibernateHelper.registerShutdownHook(); } public static SessionFactory getSessionFactory() { return sessionFactory; } private static void registerShutdownHook() { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { sessionFactory.close(); } })); } }