List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:com.fiveamsolutions.nci.commons.util.HibernateHelper.java
License:Open Source License
/** * This builds both the configuration and the session factory. *///from ww w. j a va 2s .c o m public synchronized void initialize() { if (configuration == null) { try { configuration = new AnnotationConfiguration(); initializeConfig(); // We call buildSessionFactory twice, because it appears that the annotated classes are // not 'activated' in the config until we build. The filters required the classes to // be present, so we throw away the first factory and use the second. If this is // removed, you'll likely see a NoClassDefFoundError in the unit tests SessionFactory sf = configuration.buildSessionFactory(); sf.close(); modifyConfig(); buildSessionFactory(); } catch (HibernateException e) { LOG.error(e.getMessage(), e); throw new ExceptionInInitializerError(e); } } }
From source file:com.googlecode.sarasvati.hib.util.SarasvatiSchemaTool.java
License:Open Source License
public Dialect getDialect() { if (dialect == null) { final SessionFactory sessionFactory = config.buildSessionFactory(); try {//from w w w.j a va2 s .c o m dialect = getDialect(sessionFactory); } finally { sessionFactory.close(); } } return dialect; }
From source file:com.hazelcast.hibernate.CustomPropertiesTest.java
License:Open Source License
@Test public void testNativeClient() throws Exception { TestHazelcastFactory factory = new TestHazelcastFactory(); Config config = new ClasspathXmlConfig("hazelcast-custom.xml"); HazelcastInstance main = factory.newHazelcastInstance(config); Properties props = getDefaultProperties(); props.remove(CacheEnvironment.CONFIG_FILE_PATH_LEGACY); props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName()); props.setProperty(CacheEnvironment.USE_NATIVE_CLIENT, "true"); props.setProperty(CacheEnvironment.NATIVE_CLIENT_GROUP, "dev-custom"); props.setProperty(CacheEnvironment.NATIVE_CLIENT_PASSWORD, "dev-pass"); props.setProperty(CacheEnvironment.NATIVE_CLIENT_ADDRESS, "localhost"); props.setProperty(CacheEnvironment.CONFIG_FILE_PATH, "hazelcast-client-custom.xml"); HazelcastMockInstanceLoader loader = new HazelcastMockInstanceLoader(); loader.configure(props);//from w ww.ja v a 2s . c o m loader.setInstanceFactory(factory); SessionFactory sf = createSessionFactory(props, loader); HazelcastInstance hz = HazelcastAccessor.getHazelcastInstance(sf); assertTrue(hz instanceof HazelcastClientProxy); assertEquals(1, main.getCluster().getMembers().size()); HazelcastClientProxy client = (HazelcastClientProxy) hz; ClientConfig clientConfig = client.getClientConfig(); assertEquals("dev-custom", clientConfig.getGroupConfig().getName()); assertEquals("dev-pass", clientConfig.getGroupConfig().getPassword()); assertTrue(clientConfig.getNetworkConfig().isSmartRouting()); assertTrue(clientConfig.getNetworkConfig().isRedoOperation()); factory.newHazelcastInstance(config); assertEquals(2, hz.getCluster().getMembers().size()); main.shutdown(); Thread.sleep(1000 * 1); // let client to reconnect assertEquals(1, hz.getCluster().getMembers().size()); Session session = sf.openSession(); Transaction tx = session.beginTransaction(); session.save(new DummyEntity(1L, "dummy", 0, new Date())); tx.commit(); session.close(); sf.close(); factory.shutdownAll(); }
From source file:com.hazelcast.hibernate.CustomPropertiesTest.java
License:Open Source License
@Test public void testNamedInstance() { TestHazelcastFactory factory = new TestHazelcastFactory(); Config config = new Config(); config.setInstanceName("hibernate"); HazelcastInstance hz = factory.newHazelcastInstance(config); Properties props = getDefaultProperties(); props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName()); props.put(CacheEnvironment.HAZELCAST_INSTANCE_NAME, "hibernate"); props.put(CacheEnvironment.SHUTDOWN_ON_STOP, "false"); HazelcastMockInstanceLoader instanceLoader = new HazelcastMockInstanceLoader(); instanceLoader.configure(props);/*from w w w . j ava2 s. co m*/ instanceLoader.setInstanceFactory(factory); final SessionFactory sf = createSessionFactory(props, instanceLoader); assertTrue(hz.equals(HazelcastAccessor.getHazelcastInstance(sf))); sf.close(); assertTrue(hz.getLifecycleService().isRunning()); factory.shutdownAll(); }
From source file:com.helper.GetVdtlData.java
/** * @param args the command line arguments *//*from w w w. j a v a 2 s . c o m*/ public static void main(String[] args) { // TODO code application logic here SessionFactory oldsessionFactory = NewHibernateUtil.getOldSessionFactory(); Session session = oldsessionFactory.openSession(); List<Tbldonor> donorList = session.createQuery("from Tbldonor").list(); List<Tblarea> areaList = session.createQuery("from Tblarea").list(); List<Tblaccount> accountList = session.createQuery("from Tblaccount").list(); try { SetDonorData(donorList); // setArea(areaList); // setAccount(accountList); } catch (Exception e) { e.printStackTrace(); } session.close(); oldsessionFactory.close(); }
From source file:com.helper.GetVdtlData.java
private static void setArea(List<Tblarea> areaList) { System.out.println("---seting area size---->" + areaList.size()); SessionFactory newsessionFactory = NewHibernateUtil.getNewSessionFactory(); Session session = newsessionFactory.openSession(); Transaction transaction = session.beginTransaction(); for (int i = 0; i < areaList.size(); i++) { AreaManagement areaManagement = new AreaManagement(); Tblarea arae = areaList.get(i);/*from w w w .j av a 2 s .co m*/ System.out.println("area id----->" + arae.getId() + "----name---" + arae.getName()); areaManagement.setAreaName(arae.getName()); areaManagement.setDRecordEnddate(new Date()); areaManagement.setDRecordStartdate(new Date()); areaManagement.setMakerId(0); areaManagement.setSystemDatetime(new Date()); areaManagement.setIsDeleted((byte) 0); session.saveOrUpdate(areaManagement); System.out.println("---------------------saved"); } transaction.commit(); session.close(); newsessionFactory.close(); }
From source file:com.hibernate.app.Program.java
/** * @param args the command line arguments *//*from www .j ava 2 s . c o m*/ public static void main(String[] args) { Configuration configuration = new Configuration().configure("resources/hibernate.cfg.xml"); StandardServiceRegistryBuilder registry = new StandardServiceRegistryBuilder(); registry.applySettings(configuration.getProperties()); ServiceRegistry serviceRegistry = registry.build(); SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry); Session session = sessionFactory.openSession(); //Transaction trans=session.beginTransaction(); //session.save(new Discount(0,"50% OFF",50,null,true)); //trans.commit(); List<Discount> discounts = session.getNamedQuery("Discount.findAll").list(); discounts.forEach(d -> { System.out.println(d.getDiscountTitle()); }); session.close(); sessionFactory.close(); System.out.println("Finish"); System.exit(0); }
From source file:com.jc.elementos.controller.DAOTrabajador.java
public String guardar(Trabajador t) { //pasos para la transaccin SessionFactory factory = Utilidadeshibernate.getSessionFactory(); Session sesion = factory.openSession(); Transaction tx = sesion.beginTransaction(); sesion.save(t);/* www . j av a2 s. co m*/ tx.commit(); factory.close(); return "trabajador guardado"; }
From source file:com.jc.elementos.controller.DAOTrabajador.java
public String actualizar(Trabajador t) { //pasos para la transaccin SessionFactory factory = Utilidadeshibernate.getSessionFactory(); Session sesion = factory.openSession(); Transaction tx = sesion.beginTransaction(); sesion.update(t);/*from ww w . j av a 2s .c o m*/ tx.commit(); factory.close(); return "trabajador guardado"; }
From source file:com.kzone.hibernatefilter.Hibernatefilter.java
/** * @param args the command line arguments *//* w w w . j a v a 2s . c o m*/ public static void main(String[] args) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session openSession = sessionFactory.openSession(); Searcher<Bank> bankSearcher = Searcher.createSearcher(openSession, Bank.class); List<Bank> search = bankSearcher.and(new ILikeFilter("bankName", "test")) .and(new EqualsFilter("isActive", Boolean.TRUE)).search(); sessionFactory.close(); }