List of usage examples for org.hibernate Session persist
void persist(Object object);
From source file:daos.userBookDaos.java
static public boolean insertUserBookDaos(Userbook userbook) { Session session = ConnectionFactory.getuserBookSession(); session.beginTransaction();// w w w .ja v a2s .c om session.persist(userbook); session.getTransaction().commit(); session.close(); return true; }
From source file:daos.UserBorrowBookDaos.java
static public boolean insertUserBorrowBook(Userborrowbook borrowbook) { Session session = ConnectionFactory.getUserBorrowBookSession(); session.beginTransaction();/*from w ww.ja v a2 s . c o m*/ session.persist(borrowbook); session.getTransaction().commit(); session.close(); return true; }
From source file:daos.UserMessageDaos.java
static public boolean insertUserMessage(Usermessage usermessage) { Session session = ConnectionFactory.getUserMessageSession(); session.beginTransaction();/*from w ww . ja v a 2s . co m*/ session.persist(usermessage); session.getTransaction().commit(); session.close(); return true; }
From source file:database.services.common.DAOBase.java
public void add(ElementType element) { Session session = this.factory.openSession(); Transaction tx = null;//w w w . j a v a 2s .c om try { tx = session.beginTransaction(); session.persist(element); tx.commit(); } catch (Exception ex) { if (tx != null) tx.rollback(); throw ex; } finally { session.close(); } }
From source file:de.dominikschadow.webappsecurity.daos.CustomerDAO.java
License:Apache License
public void createCustomer(Customer customer) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); session.persist(customer); tx.commit();// ww w . j av a2 s .com session.close(); }
From source file:de.fau.osr.core.db.dao.impl.AbstractDefaultDao.java
License:Open Source License
/** * apply persistence operation <tt>dbOperation</tt> to <tt>obj</tt> * * @param dbOperation operation to apply * @param obj object to apply to * @return true if success, false otherwise *//*from w w w . j a va2 s.c om*/ protected boolean persist(DBOperation dbOperation, EntityClass obj) { try { Session session = sessionFactory.openSession(); Transaction t = null; try { t = session.beginTransaction(); switch (dbOperation) { case ADD: session.persist(obj); break; case UPDATE: session.update(obj); break; case DELETE: session.delete(obj); break; } t.commit(); } catch (HibernateException e) { if (t != null) { t.rollback(); } throw e; } finally { session.close(); } } catch (RuntimeException re) { re.printStackTrace(); return false; } return true; }
From source file:de.ingrid.portal.portlets.mdek.MdekPortalAdminPortlet.java
License:EUPL
public void processActionCreateCatalog(ActionRequest request, ActionResponse actionResponse) throws PortletException, IOException { String plugId = request.getParameter("plugId"); String userName = request.getParameter("userName"); if (plugId == null || userName == null) { return;/*from ww w. j ava2 s . c o m*/ } // Create a new UserData object IMdekCallerSecurity mdekCallerSecurity = MdekCallerSecurity.getInstance(); IngridDocument catAdminDoc = mdekCallerSecurity.getCatalogAdmin(plugId, userName); IngridDocument catAdmin = MdekUtils.getResultFromResponse(catAdminDoc); UserData user = new UserData(); user.setAddressUuid((String) catAdmin.get(MdekKeys.UUID)); user.setPlugId(plugId); user.setPortalLogin(userName); // Try to add the role 'mdek' to the user 'userName' try { roleManager.addRoleToUser(userName, "mdek"); } catch (SecurityException e) { log.error("Could not add role 'mdek' to user with name '" + userName + "'"); throw new PortletException("Could not add role 'mdek' to user with name '" + userName + "'", e); } // Role was successfully added, store the user in the mdek db Session s = HibernateUtil.currentSession(); try { s.beginTransaction(); s.persist(user); s.getTransaction().commit(); } catch (HibernateException e) { // Hibernate Exception. Rollback the role change and the transaction if (s.getTransaction() != null && s.getTransaction().wasCommitted()) { s.getTransaction().rollback(); } try { roleManager.removeRoleFromUser(userName, "mdek"); } catch (SecurityException se) { log.error("Error while connectiong a new catalog. The user '" + userName + "' could not be created in the 'mdek' database. " + "Additionaly the user received the role 'mdek' which could not be removed.", se); } throw new PortletException("Error while connectiong a new catalog. The user '" + userName + "' could not be created in the 'mdek' database. " + "Additionaly the user received the role 'mdek' which could not be removed.", e); } finally { HibernateUtil.closeSession(); this.state = STATE.START; } }
From source file:de.rwth.idsg.xsharing.router.persistence.repository.AbstractRepository.java
License:Open Source License
protected <T> void saveBatch(List<T> entities) throws DatabaseException { Session session = null; Transaction tx = null;// w w w. ja v a 2s . c om try { session = getEntityManager().unwrap(Session.class); // session.setCacheMode(CacheMode.IGNORE); tx = session.beginTransaction(); int counter = 0; for (T p : entities) { session.persist(p); if (++counter % BATCH_SIZE == 0) { // flush a batch of inserts and release memory session.flush(); session.clear(); } } tx.commit(); } catch (Exception e) { if (tx != null) { try { tx.rollback(); } catch (RuntimeException rbe) { log.error("Couldn't roll back transaction", rbe); } } throw new DatabaseException("Batch saving of entity list failed: " + e.getMessage()); } finally { if (session != null && session.isOpen()) { try { session.close(); } catch (HibernateException e) { log.error("Error while trying to close the session", e); } } } }
From source file:de.uniwue.info6.database.map.daos.DaoTools.java
License:Apache License
public void persist(T transientInstance, Session session) { log.debug("persisting T instance"); try {/* w ww .jav a2s . c o m*/ session.persist(transientInstance); log.debug("persist successful"); } catch (RuntimeException re) { log.error("persist failed", re); throw re; } }
From source file:demo.springmvc.blog.dao.PostDaoImpl.java
@Override public void addPost(Post p) { Session session = this.sessionFactory.getCurrentSession(); session.persist(p); logger.info("Post saved successfully, Post Details=" + p); }