List of usage examples for org.hibernate SessionFactory getCurrentSession
Session getCurrentSession() throws HibernateException;
From source file:automatedbillingsoftware_DA.User_DA.java
public Users fetchUserById(int id) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); Query query = session.createQuery("from Users where status=:status and userid=:id"); query.setParameter("status", 1); query.setParameter("userid", id); List<Users> list = (List<Users>) query.list(); // session.saveOrUpdate(users); beginTransaction.commit();/*w w w .ja v a 2 s . c o m*/ // return users; return (Users) list.get(0); }
From source file:automatedbillingsoftware_DA.User_DA.java
public void deleteUser(int id) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); Users userId = fetchUserById(id);//w ww . j a v a 2s .c om userId.setStatus(0); session.update(userId); session.flush(); // session.saveOrUpdate(users); beginTransaction.commit(); // return users; }
From source file:automatedbillingsoftware_DA.User_DA.java
public void updateUser(Users user) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); session.update(user);/*from w ww .j a va2 s .c o m*/ session.flush(); // session.saveOrUpdate(users); beginTransaction.commit(); // return users; }
From source file:br.com.agendamento.model.daos.AbstractFacade.java
public Connection getConnection() throws SQLException { Session session = em.unwrap(Session.class); SessionFactory sf = session.getSessionFactory(); SessionImplementor si = (SessionImplementor) sf.getCurrentSession(); JdbcConnectionAccess access = si.getJdbcConnectionAccess(); return access.obtainConnection(); }
From source file:br.udesc.ceplan.prog3.hibernate.ExemploHibernate.java
/** * @param args the command line arguments *///from w w w .j a v a 2s . c o m public static void main(String[] args) throws Exception { SessionFactory sessFact = NewHibernateUtil.getSessionFactory(); Session session = sessFact.getCurrentSession(); org.hibernate.Transaction tr = session.beginTransaction(); Employee emp; emp = new Employee(); emp.setEmpName("TESTE 01"); emp.setEmpMobileNos("11111111111"); emp.setEmpAddress("ENDEREO TESTE 01"); session.save(emp); emp = new Employee(); emp.setEmpName("TESTE 02"); emp.setEmpMobileNos("22222222222"); emp.setEmpAddress("ENDEREO TESTE 02"); session.save(emp); emp = new Employee(); emp.setEmpName("TESTE 03"); emp.setEmpMobileNos("333333333333"); emp.setEmpAddress("ENDEREO TESTE 03"); session.save(emp); tr.commit(); System.out.println("Successfully inserted"); printData(); sessFact.close(); }
From source file:br.udesc.ceplan.prog3.hibernate.ExemploHibernate.java
public static void printData() throws Exception { SessionFactory sessFact = NewHibernateUtil.getSessionFactory(); Session session = sessFact.getCurrentSession(); org.hibernate.Transaction tr = session.beginTransaction(); CriteriaQuery cq = session.getCriteriaBuilder().createQuery(Employee.class); cq.from(Employee.class); List<Employee> employeeList = session.createQuery(cq).getResultList(); for (Employee employee : employeeList) { logger.info("ID: " + employee.getId()); logger.info("Name: " + employee.getEmpName()); }//from w ww . ja va 2 s . c om tr.commit(); System.out.println("Data printed"); }
From source file:ca.usask.gmcte.util.HibernateUtil.java
License:Open Source License
private static boolean connectionOkay(SessionFactory factory) { try {//from w w w. j av a 2 s . c om Session session = factory.getCurrentSession(); session.beginTransaction(); session.get(Organization.class, -1); session.getTransaction().commit(); return true; } catch (Exception e) { logger.fatal("ERROR IN connectionOkay ", e); if (!emailSent) { HTMLTools.sendEmailMessage("guus.v@usask.ca", "ulc_events@usask.ca", "Connection error in Currimap!", "You better go and check it ouT"); emailSent = true; } return false; } }
From source file:ch.algotrader.util.HibernateUtil.java
License:Open Source License
public static Serializable getNextId(SessionFactory sessionFactory, Class<?> type) { AbstractEntityPersister persister = getEntityPersister(sessionFactory, type); return persister.getIdentifierGenerator().generate((SessionImpl) sessionFactory.getCurrentSession(), null); }
From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AuthorizationDAOFactory.java
License:Apache License
public void disableSecondLevelCacheForSession() { SessionFactory sessionFactory = persistencyResources.getSessionFactoryOrNull(); sessionFactory.getCurrentSession().setCacheMode(CacheMode.IGNORE); }
From source file:com.algoTrader.util.HibernateUtil.java
License:Open Source License
public static boolean lock(SessionFactory sessionFactory, Object target) { Session session = sessionFactory.getCurrentSession(); try {//from w ww.j a v a 2s.co m session.buildLockRequest(LockOptions.NONE).lock(target); return true; } catch (NonUniqueObjectException e) { // different object with the same identifier value was already associated with the session return false; } }