List of usage examples for org.hibernate Session merge
Object merge(Object object);
From source file:com.floreantpos.ui.model.PizzaItemForm.java
License:Open Source License
@Override protected void updateView() { MenuItem menuItem = getBean(); if (menuItem.getId() != null && !Hibernate.isInitialized(menuItem.getMenuItemModiferGroups())) { //initialize food item modifer groups. MenuItemDAO dao = new MenuItemDAO(); Session session = dao.getSession(); menuItem = (MenuItem) session.merge(menuItem); Hibernate.initialize(menuItem.getMenuItemModiferGroups()); session.close();//w ww . j a v a 2 s . com } // terminalList.selectItems(menuItem.getTerminals()); orderList.selectItems(menuItem.getOrderTypeList()); tfName.setText(menuItem.getName()); tfDescription.setText(menuItem.getDescription()); tfTranslatedName.setText(menuItem.getTranslatedName()); tfBarcode.setText(menuItem.getBarcode()); tfStockCount.setText(String.valueOf(menuItem.getStockAmount())); chkVisible.setSelected(menuItem.isVisible()); cbShowTextWithImage.setSelected(menuItem.isShowImageOnly()); cbDisableStockCount.setSelected(menuItem.isDisableWhenStockAmountIsZero()); ImageIcon menuItemImage = menuItem.getImage(); if (menuItemImage != null) { lblImagePreview.setIcon(menuItemImage); } if (menuItem.getId() == null) tfDefaultSellPortion.setText(String.valueOf(100)); else tfDefaultSellPortion.setText(String.valueOf(menuItem.getDefaultSellPortion())); cbGroup.setSelectedItem(menuItem.getParent()); cbTax.setSelectedItem(menuItem.getTax()); cbPrinterGroup.setSelectedItem(menuItem.getPrinterGroup()); if (menuItem.getSortOrder() != null) { tfSortOrder.setText(menuItem.getSortOrder().toString()); } Color buttonColor = menuItem.getButtonColor(); if (buttonColor != null) { btnButtonColor.setBackground(buttonColor); btnTextColor.setBackground(buttonColor); } if (menuItem.getTextColor() != null) { btnTextColor.setForeground(menuItem.getTextColor()); } }
From source file:com.floreantpos.ui.views.order.OrderView.java
License:Open Source License
public void updateTableNumber() { Session session = null; org.hibernate.Transaction transaction = null; try {// w ww . j a v a 2 s . c o m Ticket thisTicket = currentTicket; TableSelectorDialog dialog = TableSelectorFactory.createTableSelectorDialog(thisTicket.getOrderType()); dialog.setCreateNewTicket(false); if (thisTicket != null) { dialog.setTicket(thisTicket); } dialog.openUndecoratedFullScreen(); if (dialog.isCanceled()) { return; } List<ShopTable> tables = dialog.getSelectedTables(); if (tables == null) { return; } session = TicketDAO.getInstance().createNewSession(); transaction = session.beginTransaction(); clearShopTable(session, thisTicket); session.saveOrUpdate(thisTicket); for (ShopTable shopTable : tables) { shopTable.setServing(true); session.merge(shopTable); thisTicket.addTable(shopTable.getTableNumber()); } session.merge(thisTicket); transaction.commit(); actionUpdate(); } catch (Exception e) { PosLog.error(getClass(), e); transaction.rollback(); } finally { if (session != null) { session.close(); } } }
From source file:com.github.shyiko.rook.it.h4com.IntegrationTest.java
License:Apache License
private void testSecondLevelCacheEviction(final boolean enableSLCS) throws Exception { ExecutionContext masterContext = ExecutionContextHolder.get("master"); ExecutionContext slaveContext = ExecutionContextHolder.get("slave"); if (enableSLCS) { replicationStream.registerListener(new SecondLevelCacheSynchronizer( new SynchronizationContext(slaveContext.getConfiguration(), slaveContext.getSessionFactory()))); }/*www.j av a 2s . c o m*/ CountDownReplicationListener countDownReplicationListener = new CountDownReplicationListener(); replicationStream.registerListener(countDownReplicationListener); final AtomicReference<Serializable> rootEntityId = new AtomicReference<Serializable>(), ignoredEntityId = new AtomicReference<Serializable>(); masterContext.execute(new Callback<Session>() { @Override public void execute(Session session) { rootEntityId.set(session.save(new RootEntity("Slytherin", new OneToOneEntity("Severus Snape"), new HashSet<OneToManyEntity>(Arrays.asList(new OneToManyEntity("Draco Malfoy"), new OneToManyEntity("Vincent Crabbe"), new OneToManyEntity("Gregory Goyle")))))); ignoredEntityId.set(session.save(new IgnoredEntity("Hufflepuff"))); session.persist(new CompositeKeyEntity((Long) rootEntityId.get(), (Long) ignoredEntityId.get())); } }); slaveContext.execute(new Callback<Session>() { @Override public void execute(Session session) { RootEntity rootEntity = (RootEntity) session.get(RootEntity.class, rootEntityId.get()); assertEquals(rootEntity.getName(), "Slytherin"); assertEquals(rootEntity.getCompositeRelations().size(), 1); } }); masterContext.execute(new Callback<Session>() { @Override public void execute(Session session) { RootEntity rootEntity = (RootEntity) session.get(RootEntity.class, rootEntityId.get()); rootEntity.setName("Slytherin House"); rootEntity.getCompositeRelations().clear(); session.merge(rootEntity); } }); countDownReplicationListener.waitFor(UpdateRowsReplicationEvent.class, 1, DEFAULT_TIMEOUT); countDownReplicationListener.waitFor(DeleteRowsReplicationEvent.class, 1, DEFAULT_TIMEOUT); slaveContext.execute(new Callback<Session>() { @Override public void execute(Session session) { RootEntity rootEntity = (RootEntity) session.get(RootEntity.class, rootEntityId.get()); assertEquals(rootEntity.getName(), enableSLCS ? "Slytherin House" : "Slytherin"); assertEquals(rootEntity.getCompositeRelations().size(), enableSLCS ? 0 : 1); } }); masterContext.execute(new Callback<Session>() { @Override public void execute(Session session) { session.delete(session.get(RootEntity.class, rootEntityId.get())); } }); countDownReplicationListener.waitFor(DeleteRowsReplicationEvent.class, 2, DEFAULT_TIMEOUT); slaveContext.execute(new Callback<Session>() { @Override public void execute(Session session) { RootEntity rootEntity = (RootEntity) session.get(RootEntity.class, rootEntityId.get()); assertTrue(enableSLCS == (rootEntity == null)); } }); }
From source file:com.globalsight.everest.webapp.pagehandler.tasks.TaskHelper.java
License:Apache License
/** * Retrieve the task object from the session manager and merge it against * the current Hibernate session.//from w ww . ja va 2s . c o m */ public static TaskImpl retrieveMergeObject(HttpSession p_httpSession, String key) { TaskImpl obj = (TaskImpl) retrieveObject(p_httpSession, key); if (obj == null) return null; Session hibSession = HibernateUtil.getSession(); TaskImpl newObj = (TaskImpl) hibSession.merge(obj); copyTaskValue(obj, newObj); // Update the session - merge() returns a new instance storeObject(p_httpSession, key, newObj); return newObj; }
From source file:com.globalsight.persistence.hibernate.HibernateUtil.java
License:Apache License
/** * Copy the state of the given object onto the persistent object with the same * identifier. If there is no persistent instance currently associated with * the session, it will be loaded. Return the persistent instance. If the * given instance is unsaved, save a copy of and return it as a newly persistent * instance. The given instance does not become associated with the session. * This operation cascades to associated instances if the association is mapped * with <tt>cascade="merge"</tt>.<br> * <br>/*w w w .j ava 2 s . co m*/ * The semantics of this method are defined by JSR-220. * * @param object a detached instance with state to be copied * @return an updated persistent instance */ public static void merge(Object object) throws HibernateException { if (object == null) { return; } Session session = getSession(); Transaction tx = getTransaction(); try { session.merge(object); commit(tx); } catch (HibernateException e) { rollback(tx); throw e; } }
From source file:com.gmail.vasylvovkastr.dataaccessobject.ProductDAO.java
public static User updateProduct(User user) { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); session.beginTransaction();//from w ww .j av a 2s. co m session.merge(user); session.getTransaction().commit(); session.close(); return user; }
From source file:com.herval.gestaoefetivo.daos.GenericDAO.java
public void merge(Entidade entidade) { Session sessao = HibernateUtil.getSessionFactory().openSession(); Transaction transacao = null;/*ww w . j a v a2 s . com*/ try { transacao = sessao.beginTransaction(); sessao.merge(entidade); transacao.commit(); } catch (RuntimeException erro) { if (transacao != null) { transacao.rollback(); } throw erro; } finally { sessao.close(); } }
From source file:com.hyron.poscafe.dao.BarcodeDaoImpl.java
License:Open Source License
@Override public Barcode merge(Barcode detachedInstance, Session session) throws HibernateException { log.debug("merging Barcode instance"); try {/*from w w w . ja v a 2 s. c o m*/ Barcode result = (Barcode) session.merge(detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } }
From source file:com.hyron.poscafe.dao.CashDrawerOptDaoImpl.java
License:Open Source License
@Override public CashDrawerOpt merge(CashDrawerOpt detachedInstance, Session session) throws HibernateException { log.debug("merging CashDrawerOpt instance"); try {/* ww w. j av a2s. c om*/ CashDrawerOpt result = (CashDrawerOpt) session.merge(detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } }
From source file:com.hyron.poscafe.dao.CashierDaoImpl.java
License:Open Source License
@Override public Cashier merge(Cashier detachedInstance, Session session) throws HibernateException { log.debug("merging Cashier instance"); try {// w w w . ja v a2 s . c om Cashier result = (Cashier) session.merge(detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } }