List of usage examples for org.hibernate FlushMode MANUAL
FlushMode MANUAL
To view the source code for org.hibernate FlushMode MANUAL.
Click Source Link
From source file:service.DatabaseService.java
@Override @Transactional//from w ww . j a v a 2 s . c om public Object getEntityById(String column, String table, Integer id) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); session.setFlushMode(FlushMode.MANUAL); ManagedSessionContext.bind(session); String table_capitalized = table.substring(0, 1).toUpperCase() + table.substring(1); String str_query = "from " + table_capitalized + " t where t." + column.toLowerCase() + " = :crit"; Query query = session.createQuery(str_query); query.setParameter("crit", id); //ManagedSessionContext.unbind(sessionFactory); session.flush(); if (query.list().size() == 0) return null; return query.list().get(0); }
From source file:service.DatabaseService.java
@Override @Transactional/* w ww. j a va 2s. co m*/ public void updateEntity(Object entity) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); session.setFlushMode(FlushMode.MANUAL); ManagedSessionContext.bind(session); Transaction tx = null; try { tx = session.beginTransaction(); session.merge(entity); ManagedSessionContext.unbind(HibernateUtil.getSessionFactory()); session.flush(); tx.commit(); } catch (RuntimeException e) { tx.rollback(); throw e; } finally { session.close(); } }
From source file:service.DatabaseService.java
@Override @Transactional//from w w w . ja v a 2s.c o m public void findEntitiesMatchingPartialQuery(String field, String query_text, Object entity) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); session.setFlushMode(FlushMode.MANUAL); ManagedSessionContext.bind(session); FullTextSession fullTextSession = org.hibernate.search.Search.getFullTextSession(session); Transaction tx = fullTextSession.beginTransaction(); QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(entity.getClass()).get(); org.apache.lucene.search.Query query = qb.keyword().onFields(field).matching(query_text).createQuery(); org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, entity.getClass()); List result = hibQuery.list(); if (result.size() > 0) System.out.println(result.get(0)); }
From source file:service.DatabaseService.java
@Override public List listEntity(String table) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); session.setFlushMode(FlushMode.MANUAL); ManagedSessionContext.bind(session); String table_capitalized = table.substring(0, 1).toUpperCase() + table.substring(1); String str_query = "from " + table_capitalized; Query query = session.createQuery(str_query); //ManagedSessionContext.unbind(sessionFactory); session.flush();// ww w .ja v a 2 s . c om return query.list(); }
From source file:service.DatabaseService.java
@Override public List listEntityByJoinCriteria(String table, String propertyName, String criteria_column, String criteria_text) {/*from ww w.j a v a2 s . c o m*/ SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); session.setFlushMode(FlushMode.MANUAL); ManagedSessionContext.bind(session); String table_cap = table.substring(0, 1).toUpperCase() + table.substring(1); //String str_query = "select u from Users u join u.userRoleses r where r.role='ROLE_ADMIN'"; String str_query = "select u from " + table_cap + " u join u. " + propertyName + " r where r." + criteria_column + "='" + criteria_text + "'"; Query query = session.createQuery(str_query); //ManagedSessionContext.unbind(sessionFactory); session.flush(); List aux = query.list(); return query.list(); }
From source file:service.DatabaseService.java
@Override public List listEntityByJoinIdCriteria(String table, String propertyName, String criteria_column, Integer id, String sndC, Integer sndQ) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); session.setFlushMode(FlushMode.MANUAL); ManagedSessionContext.bind(session); String table_cap = table.substring(0, 1).toUpperCase() + table.substring(1); //String str_query = "select u from Users u join u.userRoleses r where r.role='ROLE_ADMIN'"; String str_query = "select u from " + table_cap + " u join u. " + propertyName + " r where r." + criteria_column + "=" + id + "AND u." + sndC + "=" + sndQ; Query query = session.createQuery(str_query); //ManagedSessionContext.unbind(sessionFactory); session.flush();//from w w w .j av a2 s. c om List aux = query.list(); return query.list(); }
From source file:service.DatabaseService.java
public void deleteEntity(Object entity) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); //Session session = sessionFactory.openSession(); Session session = sessionFactory.getCurrentSession(); session.setFlushMode(FlushMode.MANUAL); //ManagedSessionContext.bind(session); Transaction tx = null;/* w ww .jav a2 s.c om*/ try { tx = session.beginTransaction(); //session.merge(entity); session.delete(entity); ManagedSessionContext.unbind(HibernateUtil.getSessionFactory()); session.flush(); tx.commit(); } catch (RuntimeException e) { tx.rollback(); throw e; } finally { session.close(); } }
From source file:service.DatabaseService.java
@Override public List listEntityPartialQuery(String table, ArrayList<String> columns, String query_text) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); session.setFlushMode(FlushMode.MANUAL); ManagedSessionContext.bind(session); String table_capitalized = table.substring(0, 1).toUpperCase() + table.substring(1); int cols = columns.size(); String str_query = "from " + table_capitalized + " where "; for (int i = 0; i < cols; i++) { str_query += columns.get(i) + " like :crit"; if (i < cols - 1) str_query += " or "; }/* ww w .ja v a 2s . co m*/ Query query = session.createQuery(str_query); query.setParameter("crit", "%" + query_text + "%"); session.flush(); return query.list(); }
From source file:to.etc.domui.hibernate.generic.HibernateLongSessionContext.java
License:Open Source License
/** * This override allocates a session in flushmode manual. * @see to.etc.domui.hibernate.generic.BuggyHibernateBaseContext#getSession() *//*from w w w .j av a2 s . c om*/ @Override public Session getSession() throws Exception { checkValid(); if (m_session == null) { super.getSession(); m_session.setFlushMode(FlushMode.MANUAL); } if (!m_session.isConnected()) LOG.debug("Hibernate: reconnecting session."); return m_session; }
From source file:tools.xor.service.HibernatePersistenceOrchestrator.java
License:Apache License
@Override public Object disableAutoFlush() { Object oldFlushMode = getSession().getFlushMode(); getSession().setFlushMode(FlushMode.MANUAL); return oldFlushMode; }