/** Connect to database using hibernate */ public void establishSession() { LOG.info("Opening hibernate session"); serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build(); factory = config.buildSessionFactory(serviceRegistry); session = factory.openSession(); session.setCacheMode(CacheMode.IGNORE); session.setDefaultReadOnly(sqlSourceHelper.isReadOnlySession()); }
private Session openSession(boolean readOnly) { final Session session = sessionFactory.openSession(); try { session.setDefaultReadOnly(readOnly); session.setFlushMode(FlushMode.AUTO); session.setCacheMode(CacheMode.NORMAL); ManagedSessionContext.bind(session); if (!readOnly) { session.beginTransaction(); } } finally { } return session; }
@Override public void run() { log.trace("started"); Session session = sessionFactory.withOptions().tenantIdentifier(tenantId).openSession(); session.setFlushMode(FlushMode.MANUAL); session.setCacheMode(cacheMode); session.setDefaultReadOnly(true); try { loadAllFromQueue(session); } catch (Exception exception) { errorHandler.handleException(log.massIndexerExceptionWhileTransformingIds(), exception); } finally { producerEndSignal.countDown(); session.close(); } log.trace("finished"); }
public void setDefaultReadOnly(boolean readOnly) { session.setDefaultReadOnly(readOnly); }
private void configureSession(Session session, UnitOfWork uow) { session.setDefaultReadOnly(uow.readOnly()); session.setCacheMode(uow.cacheMode()); session.setFlushMode(uow.flushMode()); }