List of usage examples for org.hibernate Session get
Object get(String entityName, Serializable id);
From source file:bazydanych.KsiazkiTest.java
private void updateBook(Integer bookID, String title, Set heroes) { Session session = factory.openSession(); Transaction tx = null;//from w w w. j a va 2s. c o m try { tx = session.beginTransaction(); Ksiazka book = (Ksiazka) session.get(Ksiazka.class, bookID); if (title != null) { book.setTytul(title); } if (heroes != null) { book.setBohaterowie(heroes); } session.update(book); tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); fail(); } finally { session.close(); } }
From source file:bazydanych.KsiazkiTest.java
private void deleteBook(Integer bookId) { Session session = factory.openSession(); Transaction tx = null;/* w w w. ja va2 s. c o m*/ try { tx = session.beginTransaction(); Ksiazka book = (Ksiazka) session.get(Ksiazka.class, bookId); session.delete(book); tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); fail(); } finally { session.close(); } }
From source file:bazydanych.ManageEmployee.java
public void updateEmployee(Integer EmployeeID, int salary) { Session session = factory.openSession(); Transaction tx = null;//ww w.ja v a 2 s. c om try { tx = session.beginTransaction(); Employee employee = (Employee) session.get(Employee.class, EmployeeID); employee.setSalary(salary); session.update(employee); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } }
From source file:bazydanych.ManageEmployee.java
public void deleteEmployee(Integer EmployeeID) { Session session = factory.openSession(); Transaction tx = null;/* w ww . ja va 2 s. c o m*/ try { tx = session.beginTransaction(); Employee employee = (Employee) session.get(Employee.class, EmployeeID); session.delete(employee); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } }
From source file:bazydanych.OneToManyTest.java
private void updateEmployee(Integer EmployeeID, String fname, String lname, int salary, Set cert) { Session session = factory.openSession(); Transaction tx = null;/*from w w w .j av a 2 s.c o m*/ try { tx = session.beginTransaction(); Employee employee = (Employee) session.get(Employee.class, EmployeeID); if (fname != null) { employee.setFirstName(fname); } if (lname != null) { employee.setLastName(lname); } if (salary != -1) { employee.setSalary(salary); } if (cert != null) { employee.setCertificates(cert); } session.update(employee); tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); fail(); } finally { session.close(); } }
From source file:bazydanych.OneToManyTest.java
private void deleteEmployee(Integer EmployeeID) { Session session = factory.openSession(); Transaction tx = null;/*from w w w . ja v a 2s . c o m*/ try { tx = session.beginTransaction(); Employee employee = (Employee) session.get(Employee.class, EmployeeID); session.delete(employee); tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); fail(); } finally { session.close(); } }
From source file:bd.ac.seu.hibernate.FXMLDocumentController.java
@FXML private void handleSearchStudentAction(ActionEvent event) { String id = searchIdField.getText(); Session session = SessionFactorySingleton.getSessionFactory().openSession(); Student student = (Student) session.get(Student.class, id); System.out.println(student);// w ww . j a va2s .c om idField.setText(student.getId()); nameField.setText(student.getName()); }
From source file:be.facet.it.dojo.customershibernate.repository.CustomerRepository.java
@Override public Customer fetchById(long id) { Session session = this.sessionFactory.openSession(); Customer customer = session.get(Customer.class, id); session.close();/*from w ww . j a v a2 s.c om*/ return customer; }
From source file:be.facet.it.dojo.customershibernate.repository.ProductRepository.java
@Override public Product fetchById(long id) { Session session = this.sessionFactory.openSession(); Product product = session.get(Product.class, id); session.close();/*from www. j av a 2 s . c o m*/ return product; }
From source file:biomart.DAO.AdminDAO.java
public String updateOrderStatus(String orderId, String orderStatus) { Session session = Util.getSessionFactory().openSession(); OrderBean orderBean = (OrderBean) session.get(OrderBean.class, orderId); orderBean.setOrderStatus(orderStatus); session.close();//from ww w . j a v a 2 s . com if (new CommonDAO().addOrUpdateDetails(orderBean).equals("success")) { return "success"; } return null; }