private void initDialog() { lblProductName.setText(SYSTools.xx("newstocks.lblProd")); lblAcme.setText(SYSTools.xx("misc.msg.acme")); lblSideEffects.setText(SYSTools.xx("misc.msg.sideeffects")); EntityManager em = OPDE.createEM(); Query query2 = em.createQuery("SELECT m FROM ACME m ORDER BY m.name, m.city"); cmbAcme.setModel(new DefaultComboBoxModel(query2.getResultList().toArray(new ACME[] {}))); cmbAcme.setRenderer(ACMETools.getRenderer(0)); em.close(); if (product != null) { cmbAcme.setSelectedItem(product.getACME()); } txtName.setText(product.getText()); txtSideEffects.setText(product.getSideEffects()); }
private void btnOKActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnOKActionPerformed if (!saveOK()) return; EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedProducts myProduct = em.merge(product); myProduct.setText(txtName.getText().trim()); myProduct.setSideEffects(txtSideEffects.getText().trim()); myProduct.setACME(em.merge((ACME) cmbAcme.getSelectedItem())); for (TradeForm tf : myProduct.getTradeforms()) { em.lock(em.merge(tf), LockModeType.OPTIMISTIC_FORCE_INCREMENT); for (MedPackage mp : tf.getPackages()) { em.lock(em.merge(mp), LockModeType.OPTIMISTIC_FORCE_INCREMENT); } } em.lock(myProduct, LockModeType.OPTIMISTIC); em.getTransaction().commit(); product = myProduct; } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } dispose(); // hier gehts weiter. prüf auch die anderen locks bei den anderen editoren } // GEN-LAST:event_btnOKActionPerformed