List of usage examples for org.hibernate Session delete
void delete(Object object);
From source file:beans.Catalog.java
public void deleteFilm(Film film) { Session session = hibernate.HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();//from w ww .j av a 2 s.com session.delete(film); session.getTransaction().commit(); session.close(); filteredFilmList.remove(film); changeStatusMessage("Deletion of the film was successful."); }
From source file:beans.Catalog.java
public void deleteDatastore(Datastore datastore) { Session session = hibernate.HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();/*from w w w. j av a 2s . c o m*/ session.delete(datastore); session.getTransaction().commit(); session.close(); datastoreList.remove(datastore); changeStatusMessage("Deletion of the datastore was successful."); }
From source file:bikerent.AddDeleteEntity.java
@Test public void testAUDEntity() { // ############################################# // ################## A D D #################### // ############################################# System.out.println("TEST INSERT: "); System.out.println("3 Customer (3 Personen) hinzufgen "); System.out.println("2 Female-, 1 Male-, 1 Child-Bike (4 Bikes) hinzufgen "); System.out.println("3 Helmets, 3 Chainlocks, 2 Trailer (8 Accessoires) hinzufgen "); Session session = sm.getSession(); addCustomer(session);//from w w w. ja va 2 s .c om addBikes(session); addAccessiores(session); // Committing the change in the database. session.flush(); Transaction tx = session.beginTransaction(); tx.commit(); System.out.println(" -------------------------------------------- "); System.out.println("Anzahl Bikes: " + countBikes(session)); System.out.println("Anzahl Person: " + countPerson(session)); System.out.println("Anzahl Accessoires: " + countAccessoires(session)); System.out.println("Anzahl Items: " + countItem(session)); System.out.println(" -------------------------------------------- "); assertEquals("Count of bikes must be 4: ", 4, countBikes(session)); assertEquals("Count of person must be 3: ", 3, countPerson(session)); assertEquals("Count of accessoires must be 8: ", 8, countAccessoires(session)); assertEquals("Count of item must be 12: ", 12, countItem(session)); System.out.println(printBikes(session)); // ############################################# // ############### U P D A T E ################# // ############################################# System.out.println(); System.out.println(); System.out.println(); System.out.println("TEST UPDATE: "); System.out.println("Person mit der ID 1 (Sheldon Cooper) auslesen, umbenennen und wieder auslesen"); System.out.println(printPerson(session)); custID = getFirstPersonID(session); Object object = session.load(Person.class, custID); Person p = (Person) object; System.out.println(" -------------------------------------------- "); System.out.println("Name: " + p.GetName()); Transaction tx1 = session.beginTransaction(); p.SetName("Howard", "Wolowitz"); session.update(p); session.flush(); tx1.commit(); object = session.load(Person.class, custID); p = (Person) object; System.out.println("Neuer Name: " + p.GetName()); System.out.println(" -------------------------------------------- "); System.out.println(printPerson(session)); object = session.load(Customer.class, custID); Customer c = (Customer) object; System.out.println("Neuer Name des betroffenen CUSTOMERS (Subklasse): " + c.GetName()); System.out.println(" -------------------------------------------- "); assertEquals("Count of person must be 3: ", 3, countPerson(session)); // ############################################# // ############### D E L E T E ################# // ############################################# System.out.println(); System.out.println(); System.out.println(); System.out.println("TEST DELETE: "); System.out.println("Alle Items lschen und prfen, ob noch Bikes existieren"); System.out.println(" -------------------------------------------- "); System.out.println("Momentane Anzahl an Items: " + countItem(session)); System.out.println("Momentane Anzahl an Bikes: " + countBikes(session)); List<Item> iList = session.createQuery("from Item").list(); Transaction tx2 = session.beginTransaction(); for (Item i : iList) { session.delete(i); } session.flush(); tx2.commit(); System.out.println("Neue Anzahl an Items: " + countBikes(session)); System.out.println("Neue Anzahl an Bikes: " + countBikes(session)); System.out.println(" -------------------------------------------- "); assertEquals("Count of bikes must be 0: ", 0, countBikes(session)); }
From source file:biomart.DAO.AdminDAO.java
public String removeUserDetails(String userName, long phoneNo) { Session session = Util.getSessionFactory().openSession(); System.out.println(userName + "" + phoneNo); String userId = new SalesmanDAO().getSalesmanId(userName, phoneNo); System.out.println(userId);/*w w w . ja v a 2 s . c o m*/ Transaction t = null; try { t = session.beginTransaction(); PersonalDetailsBean personalDetailsBean = (PersonalDetailsBean) session.load(PersonalDetailsBean.class, userId); System.out.println(personalDetailsBean.toString()); session.delete(personalDetailsBean); t.commit(); } catch (HibernateException e) { if (t != null) { t.rollback(); } e.printStackTrace(); return "fail"; } finally { session.close(); } return "success"; }
From source file:bookstore.dao.generic.GenericDAOImpl.java
public void delete(T entity) { Session hibernateSession = this.getSession(); hibernateSession.delete(entity); }
From source file:br.al.contractmanager.dao.UsuarioDao.java
public boolean excluir(Usuario usuario) { Session session = sessionFactory.getCurrentSession(); try {//from w w w . j a v a2s. c o m session.delete(usuario); return true; } catch (HibernateException e) { System.out.println(e.getMessage()); } return false; }
From source file:br.com.apprestaurante.dao.CategoriaProdutoDao.java
public void excluir(CategoriaProduto categoriaProduto) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction transacao = null;/*from ww w .j a v a2s . c om*/ try { transacao = session.beginTransaction(); session.delete(categoriaProduto); transacao.commit(); } catch (HibernateException e) { if (transacao != null) { transacao.rollback(); } e.printStackTrace(); throw new HibernateException(e.getMessage()); } finally { session.close(); } }
From source file:br.com.aula.dao.DepartamentoDAO.java
public void removerDepartamento(Departamento departamento) { Session session = factory.openSession(); Transaction transaction = session.beginTransaction(); session.delete(departamento); session.flush();/*from ww w. j a v a 2 s. c o m*/ transaction.commit(); session.close(); }
From source file:br.com.aula.dao.DependenteDAO.java
public void removerDependente(Dependente dependente) { Session session = factory.openSession(); Transaction transaction = session.beginTransaction(); session.delete(dependente); session.flush();//from w w w .ja v a2 s . c om transaction.commit(); session.close(); }
From source file:br.com.aula.dao.EmpresaDAO.java
public void removerEmpresa(Empresa empresa) { Session session = factory.openSession(); Transaction transaction = session.beginTransaction(); session.delete(empresa); session.flush();/*from w w w . j av a 2 s . com*/ transaction.commit(); session.close(); }