List of usage examples for org.hibernate Session get
Object get(String entityName, Serializable id);
From source file:app.dao.EmployeeDAOImpl.java
@Override public Employee getEmployeeById(Integer id) { Session session = getCurrentSession(); Transaction tx = session.beginTransaction(); Employee employee = (Employee) session.get(Employee.class, id); tx.commit();// w w w.j av a 2 s . c om return employee; }
From source file:app.datos.servicios.implementacion.InmuebleServiceImpl.java
License:Open Source License
@Override @Transactional(rollbackFor = PersistenciaException.class) public Inmueble obtenerInmueble(Integer id) throws PersistenciaException { Inmueble inmueble = null;/*w w w . j av a2s. co m*/ Session session = getSessionFactory().getCurrentSession(); try { inmueble = session.get(Inmueble.class, id); } catch (EntityNotFoundException e) { throw new ObjNotFoundException("obtener", e); } catch (Exception e) { throw new ConsultaException(e); } return inmueble; }
From source file:app.Ejer1.java
public static Seguro readSeguro(int clavePrimaria) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); Seguro seguro = (Seguro) session.get(Seguro.class, clavePrimaria); System.out.println(seguro.getNombre()); session.close();/*from w ww.ja v a2 s . c o m*/ return seguro; }
From source file:app.Ejer2.java
public static SeguroAnotaciones readSeguro(int clavePrimaria) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); SeguroAnotaciones seguro = (SeguroAnotaciones) session.get(SeguroAnotaciones.class, clavePrimaria); System.out.println(seguro.getNombre()); session.close();//from w w w . j a va 2 s . co m return seguro; }
From source file:app.model.repository.impl.UserDaoImpl.java
@Transactional @Override/* ww w.j a va 2 s . c o m*/ public User getUserById(int Id) { Session session = sessionFactory.getCurrentSession(); Transaction transaction = session.getTransaction(); try { transaction.begin(); //List<User> userList = session.createQuery("from User").list(); User user = (User) session.get(User.class, Id); transaction.commit(); return user; } catch (Exception e) { e.printStackTrace(); transaction.rollback(); } finally { if (session.isOpen()) session.close(); } return null; }
From source file:appointment.businessobject.ManageCustomer.java
public Boolean updateCustomer(Long CustomerID, String fname, String lname) { Session session = factory.openSession(); Transaction tx = null;//from w w w . j a v a 2 s. co m try { tx = session.beginTransaction(); Customer customer = (Customer) session.get(Customer.class, CustomerID); customer.setFirstName(fname); customer.setLastName(lname); session.update(customer); tx.commit(); return true; } catch (HibernateException e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); return false; } finally { session.close(); } }
From source file:appointment.businessobject.ManageCustomer.java
public Boolean deleteCustomer(Long CustomerID) { Session session = factory.openSession(); Transaction tx = null;//from ww w. ja v a 2 s. co m try { tx = session.beginTransaction(); Customer customer = (Customer) session.get(Customer.class, CustomerID); session.delete(customer); tx.commit(); return true; } catch (HibernateException e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); return false; } finally { session.close(); } }
From source file:appointment.data.ObjectFactory.java
public Object getDataResource(Class resourceClass, long id) { Session session = factory.openSession(); Object dataObject = session.get(resourceClass, new Long(id)); return dataObject; }
From source file:ar.com.hibernate.dao.Dao.java
public E buscarPorId(Pk id) { Session session = null; try {/*from w w w .ja va2 s . c o m*/ session = SessionManager.getSessionFactory().openSession(); return (E) session.get(getType(), id); } finally { if (session != null) { session.close(); } } }
From source file:au.com.nicta.ct.db.CtSession.java
License:Open Source License
public static Object getObject(Session s, Class c, int pk) { return s.get(c, pk); // TODO should use: //EntityManager find() method, as so: //em.find(Dog.class, myDogPrimaryKeyValue) }