public List<Element> getAllElements() throws SQLException { Session session = null; List<Element> studs = new ArrayList<Element>(); try { session = HibernateUtils.getSessionFactory().openSession(); studs = session.createCriteria(Element.class).list(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage(), "ќшибка I/O", JOptionPane.OK_OPTION); } finally { if (session != null && session.isOpen()) { session.close(); } } return studs; }
public void deleteElement(Element stud) throws SQLException { Session session = null; try { session = HibernateUtils.getSessionFactory().openSession(); session.beginTransaction(); session.delete(stud); session.getTransaction().commit(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage(), "ќшибка I/O", JOptionPane.OK_OPTION); } finally { if (session != null && session.isOpen()) { session.close(); } } }
public Element getElementById(Long id) throws SQLException { Session session = null; Element stud = null; try { session = HibernateUtils.getSessionFactory().openSession(); stud = (Element) session.load(Element.class, id); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage(), "ќшибка I/O", JOptionPane.OK_OPTION); } finally { if (session != null && session.isOpen()) { session.close(); } } return stud; }