List of usage examples for org.hibernate Session merge
Object merge(Object object);
From source file:eu.interedition.text.Text.java
License:Apache License
public static Text create(Session session, Annotation layer, Text.Type type) { Text text = new Text(); text.setLayer(layer);/*from w w w.j ava2 s . c o m*/ text.setType(type); text.setContent(Hibernate.getLobCreator(session).createClob("")); text.setLength(0); text = (Text) session.merge(text); session.flush(); session.refresh(text); text.setDigest(NULL_DIGEST); return text; }
From source file:eu.musesproject.windowsclient.model.DBManager.java
License:Apache License
public void insertCredentials(String deviceId, String userName, String password) { try {/*from w w w . j a v a 2 s .c om*/ logger.log(Level.INFO, MUSES_TAG + ":persisting object instance"); Session session = getSessionFactory().openSession(); boolean isUserAuthenticated = isUserAuthenticated(deviceId, userName, password); if (!isUserAuthenticated) { Transaction trans = null; try { trans = session.beginTransaction(); UserCredentials userCredential = new UserCredentials(); userCredential.setUsername(userName); userCredential.setPassword(password); userCredential.setDeviceId(deviceId); session.save(userCredential); trans.commit(); } catch (Exception e) { if (trans != null) trans.rollback(); e.printStackTrace(); } finally { if (session != null) session.close(); } } else { Transaction trans = null; try { trans = session.beginTransaction(); UserCredentials userCredential = new UserCredentials(); userCredential.setUsername(userName); userCredential.setPassword(password); userCredential.setDeviceId(deviceId); session.merge(userCredential); trans.commit(); } catch (Exception e) { if (trans != null) trans.rollback(); e.printStackTrace(); } finally { if (session != null) session.close(); } } logger.log(Level.INFO, MUSES_TAG + ":persist successful"); } catch (RuntimeException re) { logger.log(Level.ERROR, MUSES_TAG + ":persist failed" + re); throw re; } }
From source file:fr.utbm.projetlo54.repository.HibernateClientDAO.java
/** * Adds a client to the database and returns its id. * /*from w w w .j a va2 s . c o m*/ * @param c the new client to add to the database * @return the generated id for the new client or -1 if an error occurred */ public int addClient(Client c) { Session session; session = HibernateUtil.getSessionFactory().openSession(); int ccode = -1; try { session.beginTransaction(); Client newClient = (Client) session.merge(c); session.getTransaction().commit(); ccode = newClient.getId(); } catch (HibernateException e) { e.printStackTrace(); if (session.getTransaction() != null) { try { session.getTransaction().rollback(); } catch (HibernateException e2) { e2.printStackTrace(); } } } finally { if (session != null) { try { session.close(); } catch (Exception e) { System.out.println(e); } } } return ccode; }
From source file:fr.utbm.projetlo54.repository.HibernateCourseSessionDAO.java
/** * Adds a course session to the database and returns its id. * //from w w w .j a v a 2 s . c o m * @param cs the new course session to add to the database * @return the generated id for the new course session or -1 if an error occurred */ public int addCourseSession(CourseSession cs) { Session session; session = HibernateUtil.getSessionFactory().openSession(); int csid = -1; try { session.beginTransaction(); System.out.println(cs.getLocation()); session.merge(cs.getLocation()); session.merge(cs); session.getTransaction().commit(); csid = cs.getId(); } catch (HibernateException e) { e.printStackTrace(); if (session.getTransaction() != null) { try { session.getTransaction().rollback(); } catch (HibernateException e2) { e2.printStackTrace(); } } } finally { if (session != null) { try { session.close(); } catch (Exception e) { e.printStackTrace(); } } } return csid; }
From source file:fr.utbm.projetlo54.repository.HibernateLocationDAO.java
/** * Adds a location to the database and returns its id. * // w ww. ja v a 2 s . c o m * @param l the new location to add to the database * @return the generated id for the new course session or -1 if an error occurred */ public int addLocation(Location l) { Session session; session = HibernateUtil.getSessionFactory().openSession(); int lid = -1; try { session.beginTransaction(); Location newL = (Location) session.merge(l); session.getTransaction().commit(); lid = newL.getId(); } catch (HibernateException e) { e.printStackTrace(); if (session.getTransaction() != null) { try { session.getTransaction().rollback(); } catch (HibernateException e2) { e2.printStackTrace(); } } } finally { if (session != null) { try { session.close(); } catch (Exception e) { System.out.println(e); } } } return lid; }
From source file:fr.utbm.repository.HbernateDao.java
/** * methode permettant d'enregister un nouveau client dans la base de donnes * * @return le client est stock dans la base de donnes et le message * "sauvgarde effectu" est affich sur la console * @param c l'objet client qu'on veut enregister */// ww w .jav a2 s .c o m public void save(Client c) { Session session = HibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); session.merge(c); System.out.println("sauvergarde effectuer"); session.getTransaction().commit(); } catch (HibernateException he) { he.printStackTrace(); if (session.getTransaction() != null) { try { session.getTransaction().rollback(); } catch (HibernateException he2) { he2.printStackTrace(); } } } finally { if (session != null) { try { session.close(); } catch (HibernateException he2) { he2.printStackTrace(); } } } }
From source file:fr.utbm.repository.HbernateDao.java
/** * methode permettant de stocker dans la base de donnes un nouvel * emplacement/* ww w . j ava 2 s. com*/ * * @return l'emplacement est bien enregistr dans la base de donnes */ public void save(Location c) { Session session = HibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); session.merge(c); session.getTransaction().commit(); } catch (HibernateException he) { he.printStackTrace(); if (session.getTransaction() != null) { try { session.getTransaction().rollback(); } catch (HibernateException he2) { he2.printStackTrace(); } } } finally { if (session != null) { try { session.close(); } catch (HibernateException he2) { he2.printStackTrace(); } } } }
From source file:gov.nih.nci.caarray.dao.ArrayDaoTest.java
License:BSD License
@After public void cleanupObjects() { Transaction tx = null;//from w ww. java 2 s. c om // Save dummy objects to database. tx = this.hibernateHelper.beginTransaction(); final Session s = this.hibernateHelper.getCurrentSession(); s.delete(s.merge(DUMMY_ARRAYDESIGN_1)); s.delete(s.merge(DUMMY_ARRAYDESIGN_2)); s.delete(s.merge(DUMMY_ARRAYDESIGN_3)); s.delete(s.merge(DUMMY_ORGANIZATION3)); s.delete(s.merge(DUMMY_ASSAY_TYPE1)); s.delete(s.merge(DUMMY_ASSAY_TYPE2)); tx.commit(); }
From source file:herudi.implement.configSessionFactory.java
public void update(Object o) { Session session = this.sf.openSession(); Transaction tx = session.beginTransaction(); try {//from www. j av a 2 s.c o m session.merge(o); } catch (HibernateException e) { System.out.println("Gagal Update"); } tx.commit(); session.close(); }
From source file:io.github.dggodoi.aprendendo.java.backend.business.ChamadoBus.java
public void alterar(Chamado chamado) { Session s = HibernateUtil.getSessionFactory().openSession(); Transaction t = s.beginTransaction(); s.merge(chamado); t.commit();//www .ja va2 s.c om }