List of usage examples for org.hibernate Session load
void load(Object object, Serializable id);
From source file:com.assignment.elance.modelManager.MilestoneManager.java
public void insert(int job_id, float amount, String description, boolean send_dir) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* ww w.j a va 2 s . c om*/ Milestone milestone = new Milestone(); milestone.setJob((Job) session.load(Job.class, new Integer(job_id))); milestone.setMilestone_amount(amount); milestone.setMilestone_description(description); milestone.setMilestone_status(SystemAttributes.MileStoneStatuses.REQUEST); milestone.setSend_dir(send_dir); session.save(milestone); session.getTransaction().commit(); }
From source file:com.assignment.elance.modelManager.MilestoneManager.java
public void changeStatus(int milestone_id, int status) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* w w w . j a v a 2s . com*/ Milestone milestone = (Milestone) session.load(Milestone.class, new Integer(milestone_id)); milestone.setMilestone_status(status); session.update(milestone); session.getTransaction().commit(); }
From source file:com.autentia.intra.dao.hibernate.HibernateManagerBase.java
License:Open Source License
/** * Devuelve un objeto de negocio por clave primaria. * * @param theClass Instancia vaca del objeto que se desea recuperar * @param pk Una instancia de la clave primaria * @param session sesin de hibernate/*from w w w . ja va 2 s . c o m*/ * @return Una instancia del objeto recuperado de base de datos o null en el caso de no * encontrar ningn objeto con la clave primaria especificada */ protected <T extends Object> T getByPk(Class<T> theClass, Serializable pk, Session session) throws DataAccException { log.debug("getByPk"); T objResult = null; try { objResult = (T) session.load(theClass, pk); log.debug("Objeto con clave '" + pk + "' recuperado"); return (T) objResult; } catch (Exception ex) { String msg = "Error recuperando el objeto de tipo '" + theClass + "' con clave primaria '" + pk + "': "; log.error("Error recuperando el objeto con clave '" + pk + "': " + msg); throw new DataAccException(msg, ex); } }
From source file:com.autentia.intra.dao.hibernate.HibernateManagerBase.java
License:Open Source License
/** * Elimina un objeto de negocio de base de datos * * @param obj el objeto de negocio a eliminar * @param pk clave primaria del objeto de negocio a eliminar * @deprecated use this method only from derived classes, and use delete() methods in derived classes from other places *//*from w w w. j av a 2 s . com*/ public void delete(Object obj, Serializable pk) throws DataAccException { log.debug("delete"); Class clazz = obj.getClass(); Session session = null; try { session = HibernateUtil.currentSession(); session.beginTransaction(); // Cargamos el objeto antiguo Object objOld = session.load(clazz, pk); log.debug("objeto con clave '" + pk + "' recuperado"); // Borramos session.delete(objOld); session.getTransaction().commit(); log.debug("objeto con clave '" + pk + "' correctamente eliminado"); if (this.cacheable) HibernateManagerBase.removeCacheFor(clazz.getName()); doAfterDelete(pk); } catch (Exception ex) { StringBuffer msg = new StringBuffer("Error borrando el objeto '"); msg.append(pk); log.debug("error eliminando el objeto '" + pk + "': " + msg.toString()); throw new DataAccException(msg.toString(), ex); } /*finally{ HibernateUtil.closeSession(session); }*/ }
From source file:com.autentia.tnt.dao.hibernate.HibernateManagerBase.java
License:Open Source License
/** * Elimina un objeto de negocio de base de datos * @deprecated use this method only from derived classes, and use delete() methods in derived classes from other places * @param obj el objeto de negocio a eliminar * @param pk clave primaria del objeto de negocio a eliminar */// ww w . j a va2 s. com public void delete(Object obj, Serializable pk) throws DataAccException { log.debug("delete"); Class clazz = obj.getClass(); Session session = null; try { session = HibernateUtil.getSessionFactory().getCurrentSession(); // Cargamos el objeto antiguo Object objOld = session.load(clazz, pk); log.debug("objeto con clave '" + pk + "' recuperado"); // Borramos session.delete(objOld); log.debug("objeto con clave '" + pk + "' correctamente eliminado"); if (this.cacheable) HibernateManagerBase.removeCacheFor(clazz.getName()); doAfterDelete(pk); } catch (Exception ex) { StringBuffer msg = new StringBuffer("Error borrando el objeto '"); msg.append(pk); log.debug("error eliminando el objeto '" + pk + "': " + msg.toString()); throw new DataAccException(msg.toString(), ex); } }
From source file:com.avectis.transportcontrol.DAO.CardHibernateDAO.java
/** * get Car object from DB using Hibernate * /*from w w w. jav a 2s . com*/ * @param id * @return Card object */ @Override public Card getCard(Long id) { Session session = sessionFactory.getCurrentSession(); return (Card) session.load(Card.class, id); }
From source file:com.avectis.transportcontrol.DAO.CarHibernateDAO.java
/** * get Car object from DB using Hibernate * // ww w .j a v a 2s . c o m * @param id * @return Car object */ @Override public Car getCar(Long id) { Session session = sessionFactory.getCurrentSession(); return (Car) session.load(Car.class, id); }
From source file:com.avectis.transportcontrol.DAO.QueueHibernateDAO.java
/** * get Queue object from DB using Hibernate * /*from w w w .j av a2s . c om*/ * @param id Long - identifier of entity object * @return Queue object */ @Override public Queue getQueue(Long id) { Session session = sessionFactory.getCurrentSession(); return (Queue) session.load(Queue.class, id); }
From source file:com.avectis.transportcontrol.DAO.UserHibernateDAO.java
@Override public UserRole getUserRole(Long id) { Session session = sessionFactory.getCurrentSession(); return (UserRole) session.load(UserRole.class, id); }
From source file:com.cantor.ipplan.server.ProfileServiceImpl.java
License:Open Source License
@Override public PUserWrapper setUserData(PUserWrapper data, int joinAction) throws Exception { PUser user = checkLogin();/* w w w .jav a 2 s. c o m*/ SessionFactory sessionFactory = (SessionFactory) getServletContext().getAttribute("sessionFactory"); Session session = sessionFactory.openSession(); try { Transaction tx = session.beginTransaction(); try { session.update(user); user.setPuserLogin(data.puserLogin); user.setPuserEmail(data.puserEmail); user.setPuserTarif(data.puserTarif); user.setPuserTaxtype(data.puserTaxtype); user.setPuserTaxpercent(data.puserTaxpercent); // ? ??- if (data.puserBoss != 0 && user.getPuserTarif() <= 0) throw new Exception( " , ? ? " + " ??- ?? (? ? )."); user.setPuserBoss(data.puserBoss); // ? ?? // ? for (PUser child : user.getChildren()) { if (!containsChildren(child, data.children)) { user.getChildren().remove(child); child.setOwner(null); session.update(child); } } // ? for (PUserWrapper u : data.children) if (!u.tempflag) { PUser pu = getUserByEmail(session, u.puserEmail); sendMessageToUser(session, user, pu, " ? , " + " ? " + user.getFullName(), Messages.MT_JOIN_TO_OWNER); } // ? ? if (joinAction != 0) { if (joinAction == 1) { PUser own = (PUser) session.load(PUser.class, data.lastSystemMessage.sender.puserId); user.setOwner(own); } // ?? deleteMessage(session, data.lastSystemMessage.messageId); } tx.commit(); return user.toClient(); } catch (Exception e) { tx.rollback(); Ipplan.error(e); throw new Exception(" ? ? ? " + user.getFullName() + ": " + e.getMessage()); } } finally { session.close(); } }