List of usage examples for org.hibernate Session evict
void evict(Object object);
From source file:gr.interamerican.bo2.impl.open.hibernate.FlushStrategy.java
License:Open Source License
/** * Flushes the session, excluding the specified objects. * //from w w w . ja v a 2s.c o m * @param object * @param session * @param excluded */ private static void flush(Object object, Session session, Set<?> excluded) { if (excluded.isEmpty()) { session.flush(); } else { /* * 1. Remove the specified object from the collection of excluded objects. */ excluded.remove(object); /* * 2. There is no way to separate dirty from clean objects, so we will * evict all objects. */ for (Object objectToEvict : excluded) { if (session.contains(objectToEvict)) { session.evict(objectToEvict); } } /* * 3. Flush the session. */ session.flush(); /* * 4. Add the evicted objects to the session. */ for (Object objectToReAttach : excluded) { if (!session.contains(objectToReAttach)) { session.update(objectToReAttach); } } } }
From source file:gr.interamerican.bo2.impl.open.hibernate.TestScenarioInvoiceHibernateOperations.java
License:Open Source License
/** * Tests evicting an attached instance./*from w w w .ja v a 2 s.c om*/ * * <li>transaction1: store * <li>transaction2: read * <li>transaction3: re-attach, modify, evict and persist * <li>transaction4: confirm operations * * @throws DataException * @throws LogicException * @throws UnexpectedException */ @Test public void testEvictingFromSession() throws DataException, LogicException, UnexpectedException { /* first, store the samples */ AbstractPersistenceOperation<Invoice> storeOp = new AbstractPersistenceOperation<Invoice>(Invoice.class) { @Override public void execute() throws LogicException, DataException { po = pw.store(po); } }; invoice = factory.sampleInvoiceFull(4); invoice.setInvoiceNo(invoiceNo); storeOp.setPo(invoice); Execute.transactional(storeOp); invoice = storeOp.getPo(); copy = factory.sampleInvoiceFull(4); copy.setInvoiceNo(copyInvoiceNo); storeOp.setPo(copy); Execute.transactional(storeOp); copy = storeOp.getPo(); /* re-attach to session, modify and update */ AbstractPersistenceOperation<Invoice> updateOp = new AbstractPersistenceOperation<Invoice>(Invoice.class) { @Override public void execute() throws LogicException, DataException { /* * re-attach with lock() * This will only work if the detached instances are unmodified. */ try { Session session = getProvider().getResource("LOCALDB", HibernateSessionProvider.class) //$NON-NLS-1$ .getHibernateSession(); session.buildLockRequest(LockOptions.NONE).lock(invoice); session.buildLockRequest(LockOptions.NONE).lock(copy); } catch (InitializationException e) { fail(e.toString()); } /* now that the objects are re-attached I can modify them */ invoice.getLines().add(factory.sampleInvoiceLine(5)); copy.getLines().add(factory.sampleInvoiceLine(5)); /* * evicting copy. Even though I will only explicitly update invoice, flush() will * also send SQL for the modifications of copy to the connection. If I do not want * to persist the modifications of copy, I have to evict it from the session. */ try { Session session = getProvider().getResource("LOCALDB", HibernateSessionProvider.class) //$NON-NLS-1$ .getHibernateSession(); session.evict(copy); } catch (InitializationException e) { fail(e.toString()); } invoice = pw.update(invoice); } }; Execute.transactional(updateOp); /* confirm results, now invoice has 5 lines and copy only 4 */ AbstractPersistenceOperation<Invoice> readOp2 = new AbstractPersistenceOperation<Invoice>(Invoice.class) { @Override public void execute() throws LogicException, DataException { po = pw.read(po); po.getLines().size(); } }; invoice = Factory.create(Invoice.class); invoice.setInvoiceNo(invoiceNo); readOp2.setPo(invoice); Execute.transactional(readOp2); invoice = readOp2.getPo(); assertTrue(invoice.getLines().size() == 5); copy = Factory.create(Invoice.class); copy.setInvoiceNo(copyInvoiceNo); readOp2.setPo(copy); Execute.transactional(readOp2); copy = readOp2.getPo(); assertTrue(copy.getLines().size() == 4); }
From source file:hibernate.AllInOneTablesTest.java
License:Open Source License
public void testTables() { Session session = sessionFactory.openSession(); session.beginTransaction();/*from w w w . j a v a 2 s. c o m*/ // final Category category = new Category(); category.setCatName(""); category.setCreateDate(new Date()); session.save(category);// ?sql insert??? assertNotNull("??Category???", category.getCatId()); // Article article = new Article(); // ? // hibernate??? article.setCategory(category); article.setTitle(""); article.setContent(""); article.setCreateDate(new Date()); article.setModifyDate(new Date()); article.setSummary("?"); article.setVisitCount(0); article.setIsPublished(Boolean.TRUE); article.setType("post"); article.setCommentStatus("open"); article.setArticleStatus("public"); article.setLink("http://localhost:8080/newblog/post/abce"); session.save(article); assertNotNull("??Article???", article.getArticleId()); // Tag tag0 = new Tag(); tag0.setTagName(""); tag0.setCreateDate(new Date()); session.save(tag0); assertNotNull("??Tag???", tag0.getTagId()); Tag tag1 = new Tag(); tag1.setTagName(""); tag1.setCreateDate(new Date()); session.save(tag1); assertNotNull("??Tag???", tag1.getTagId()); Tag tag2 = new Tag(); tag2.setTagName("?"); tag2.setCreateDate(new Date()); session.save(tag2); assertNotNull("??Tag???", tag2.getTagId()); Tag tag3 = new Tag(); tag3.setTagName(""); tag3.setCreateDate(new Date()); session.save(tag3); assertNotNull("??Tag???", tag3.getTagId()); // Set<Tag> ts = article.getTags(); ts.add(tag0); ts.add(tag1); ts.add(tag2); ts.add(tag3); // Comment comment0 = new Comment(); comment0.setCommentContent("1"); comment0.setCommentName("lichhao"); comment0.setCommentEmail("lichhaosysu@gmail.com"); comment0.setCommentUrl("http://lichhao.com/blog"); comment0.setCreateDate(new Date()); comment0.setArticle(article); session.save(comment0); Comment comment2 = new Comment(); comment2.setCommentContent("2"); comment2.setCommentName("lichhao"); comment2.setCommentEmail("lichhaosysu@gmail.com"); comment2.setCommentUrl("http://lichhao.com/blog"); comment2.setCreateDate(new Date()); session.save(comment2); Comment comment3 = new Comment(); comment3.setCommentContent("3"); comment3.setCommentName("lichhao3"); comment3.setCommentEmail("lichhaosysu@gmail.com"); comment3.setCommentUrl("http://lichhao.com/blog"); comment3.setCreateDate(new Date()); comment3.setArticle(article); session.save(comment3); Comment comment4 = new Comment(); comment4.setCommentContent("4"); comment4.setCommentName("lichhao"); comment4.setCommentEmail("lichhaosysu@gmail.com"); comment4.setCommentUrl("http://lichhao.com/blog"); comment4.setCreateDate(new Date()); session.save(comment4); Set<Comment> subComments = comment0.getSubComments(); subComments.add(comment2); subComments.add(comment4); session.getTransaction().commit(); session.close(); // ?? logger.info("??"); session = sessionFactory.openSession(); session.beginTransaction(); Article obj = (Article) session.load(Article.class, article.getArticleId()); session.delete(obj); session.flush(); Iterator<?> iterate = session.createQuery("from Tag").iterate(); Tag t = null; while (iterate.hasNext()) { t = (Tag) iterate.next(); session.delete(t); session.flush(); session.evict(t); } // hibernatesql?doReturningWork session.doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { Statement stmt = connection.createStatement(); stmt.executeUpdate("delete from category where cat_id = '" + category.getCatId() + "'"); stmt.close(); } }); session.getTransaction().commit(); session.close(); logger.info("???"); }
From source file:io.dockstore.webservice.jdbi.AbstractDockstoreDAO.java
License:Apache License
public void evict(Object entry) { Session session = currentSession(); session.evict(entry); }
From source file:it.drwolf.ridire.session.JobManager.java
License:Apache License
public void setDetachedJobId(Integer jobId) { if (jobId != null) { this.job = this.entityManager.find(Job.class, jobId); Session sess = (Session) this.entityManager.getDelegate(); sess.evict(this.job); } else {//from ww w. j a v a2s . c om this.job = null; } }
From source file:itensil.repository.hibernate.RepositoryEntity.java
License:Open Source License
/** * //from w w w .jav a2s. c om * @param node * @throws AccessDeniedException * @throws NotFoundException * @throws LockException */ public void removeNode(NodeEntity node) throws AccessDeniedException, NotFoundException, LockException { User caller = SecurityAssociation.getUser(); if (!hasPermission(caller, node, DefaultNodePermission.WRITE)) { throw new AccessDeniedException(node.getUri(), "write"); } /* perhaps a lock check here? but this guy has managed to worked without (under light use) for 2 years */ deepRemoveNode(node, node.getNodeId()); Set parKids = node.getParentNode().getChildEntities(); if (Hibernate.isInitialized(parKids)) { parKids.remove(node); } getManager().fireContentChangeEvent(node, null, ContentEvent.Type.REMOVE); Session session = HibernateUtil.getSession(); session.flush(); session.lock(node, LockMode.NONE); session.evict(node); }
From source file:itensil.workflow.activities.state.Activity.java
License:Open Source License
/** * /*from ww w . j a v a2 s . co m*/ * @param id */ public Activity changeActivityId(String id) { Session session = HibernateUtil.getSession(); String qryNames[] = { "Activity.changeIdState", "Activity.changeIdPlan", "Activity.changeIdRole", "Activity.changeIdAlert", "Activity.changeIdTimer", "FlowState.changeIdLog", "Activity.changeId" }; String oid = getId(); for (String qryName : qryNames) { Query qry = session.getNamedQuery(qryName); qry.setString("oid", oid); qry.setString("nid", id); qry.executeUpdate(); } session.evict(this); session.flush(); return (Activity) session.get(Activity.class, id); }
From source file:jp.go.nict.langrid.dao.hibernate.HibernateServiceDao.java
License:Open Source License
/** * /*ww w . ja v a 2s . c o m*/ * */ public void evictService(Service service) throws DaoException { Session session = getSession(); try { session.evict(service); } catch (HibernateException e) { logAdditionalInfo(e); throw new DaoException(e); } }
From source file:lt.bsprendimai.ddesk.ChangeDetector.java
License:Apache License
/** * Generate array of strings with I18N markup of identified changes between * the Ticket objects.//from w w w . j a v a 2s .c o m * * @param updatedTicket * Updated ticket * @param originalTicket * Original ticket * @param editor * Person that made the changes * @return array of strings with markup */ private String[] detectChanges(Ticket updatedTicket, Ticket originalTicket, Person editor) { String[] ret = new String[2]; String changeNotes = ""; String publicChangeNotes = ""; Session sess = SessionHolder.currentSession().getSess(); sess.evict(updatedTicket); sess.evict(originalTicket); Status oldStatus, newStatus; Priority oldPriority, newPriority; EventType oldType, newType; Project oldProject, newProject; ProjectModule oldProjectModule, newProjectModule; Severity oldSeverity, newSeverity; if (originalTicket.getProject() != null && originalTicket.getProject() == 0) { originalTicket.setProject(null); } if (originalTicket.getModule() != null && originalTicket.getModule() == 0) { originalTicket.setModule(null); } if (originalTicket.getStatus() != null && originalTicket.getStatus() == 0) { originalTicket.setStatus(null); } if (originalTicket.getSeverity() != null && originalTicket.getSeverity() == 0) { originalTicket.setSeverity(null); } if (originalTicket.getType() != null && originalTicket.getType() == 0) { originalTicket.setType(null); } if (originalTicket.getPriority() != null && originalTicket.getPriority() == 0) { originalTicket.setPriority(null); } if (updatedTicket.getProject() != null && updatedTicket.getProject() == 0) { updatedTicket.setProject(null); } if (updatedTicket.getModule() != null && updatedTicket.getModule() == 0) { updatedTicket.setModule(null); } if (updatedTicket.getStatus() != null && updatedTicket.getStatus() == 0) { updatedTicket.setStatus(null); } if (updatedTicket.getSeverity() != null && updatedTicket.getSeverity() == 0) { updatedTicket.setSeverity(null); } if (updatedTicket.getType() != null && updatedTicket.getType() == 0) { updatedTicket.setType(null); } if (updatedTicket.getPriority() != null && updatedTicket.getPriority() == 0) { updatedTicket.setPriority(null); } if (originalTicket.getProject() != null) { oldProject = (Project) sess.get(Project.class, originalTicket.getProject()); } else { oldProject = new Project(); oldProject.setName("{empty}"); } if (updatedTicket.getProject() != null) { newProject = (Project) sess.get(Project.class, updatedTicket.getProject()); } else { newProject = new Project(); newProject.setName("{empty}"); } if (originalTicket.getModule() != null) { oldProjectModule = (ProjectModule) sess.get(ProjectModule.class, originalTicket.getModule()); } else { oldProjectModule = new ProjectModule(); oldProjectModule.setModule("{empty}"); } if (updatedTicket.getModule() != null) { newProjectModule = (ProjectModule) sess.get(ProjectModule.class, updatedTicket.getModule()); } else { newProjectModule = new ProjectModule(); newProjectModule.setModule("{empty}"); } if (originalTicket.getStatus() != null) { oldStatus = (Status) sess.get(Status.class, originalTicket.getStatus()); } else { oldStatus = new Status(); oldStatus.setName("{empty}"); } if (updatedTicket.getStatus() != null) { newStatus = (Status) sess.get(Status.class, updatedTicket.getStatus()); } else { newStatus = new Status(); newStatus.setName("{empty}"); } if (originalTicket.getPriority() != null) { oldPriority = (Priority) sess.get(Priority.class, originalTicket.getPriority()); } else { oldPriority = new Priority(); oldPriority.setName("{empty}"); } if (updatedTicket.getPriority() != null) { newPriority = (Priority) sess.get(Priority.class, updatedTicket.getPriority()); } else { newPriority = new Priority(); newPriority.setName("{empty}"); } if (originalTicket.getType() != null) { oldType = (EventType) sess.get(EventType.class, originalTicket.getType()); } else { oldType = new EventType(); oldType.setName("{empty}"); } if (updatedTicket.getType() != null) { newType = (EventType) sess.get(EventType.class, updatedTicket.getType()); } else { newType = new EventType(); newType.setName("{empty}"); } if (originalTicket.getSeverity() != null) { oldSeverity = (Severity) sess.get(Severity.class, originalTicket.getSeverity()); } else { oldSeverity = new Severity(); oldSeverity.setName("{empty}"); } if (updatedTicket.getSeverity() != null) { newSeverity = (Severity) sess.get(Severity.class, updatedTicket.getSeverity()); } else { newSeverity = new Severity(); newSeverity.setName("{empty}"); } if (!safeEquals(originalTicket.getName(), updatedTicket.getName())) { if (originalTicket.getName() == null) { changeNotes += "{name} {setTo} %fs%" + updatedTicket.getName() + "%sf%\n"; publicChangeNotes += "{name} {setTo} %fs%" + updatedTicket.getName() + "%sf%\n"; } else { changeNotes += "{name} %fs%" + originalTicket.getName() + "%sf% {changeTo} %fs%" + updatedTicket.getName() + "%sf%\n"; publicChangeNotes += "{name} %fs%" + originalTicket.getName() + "%sf% {changeTo} %fs%" + updatedTicket.getName() + "%sf%\n"; } } if (!safeEquals(originalTicket.getProject(), updatedTicket.getProject())) { if (originalTicket.getProject() == null) { if (updatedTicket.getProject() != null) { changeNotes += "{project} {setTo} %fs%" + newProject.getName() + "%sf%\n"; } } else { changeNotes += "{project} %fs%" + oldProject.getName() + "%sf% {changeTo} %fs%" + newProject.getName() + "%sf%\n"; } } if (!safeEquals(originalTicket.getModule(), updatedTicket.getModule())) { if (originalTicket.getModule() == null) { if (updatedTicket.getModule() != null) { changeNotes += "{module} {setTo} %fs%" + newProjectModule.getModule() + "%sf%\n"; } } else { changeNotes += "{module} %fs%" + oldProjectModule.getModule() + "%sf% {changeTo} %fs%" + newProjectModule.getModule() + "%sf%\n"; } } if (!safeEquals(originalTicket.getStatus(), updatedTicket.getStatus())) { if (originalTicket.getStatus() == null) { if (updatedTicket.getStatus() != null) { changeNotes += "{status} {setTo} %fs%" + newStatus.getName() + "%sf%\n"; } } else { changeNotes += "{status} %fs%" + oldStatus.getName() + "%sf% {changeTo} %fs%" + newStatus.getName() + "%sf%\n"; } } if (!safeEquals(originalTicket.getSeverity(), updatedTicket.getSeverity())) { if (originalTicket.getSeverity() == null) { if (updatedTicket.getSeverity() != null) { changeNotes += "{severity} {setTo} %fs%" + newSeverity.getName() + "%sf%\n"; } } else { changeNotes += "{severity} %fs%" + oldSeverity.getName() + "%sf% {changeTo} %fs%" + newSeverity.getName() + "%sf%\n"; } } if (!safeEquals(originalTicket.getWorktime(), updatedTicket.getWorktime())) { if (originalTicket.getWorktime() == null) { changeNotes += "{worktime} {setTo} %fs%" + updatedTicket.getWorktime() + "%sf%\n"; publicChangeNotes += "{worktime} {setTo} %fs%" + updatedTicket.getWorktime() + "%sf%\n"; } else { changeNotes += "{worktime} %fs%" + originalTicket.getWorktime() + "%sf% {changeTo} %fs%" + updatedTicket.getWorktime() + "%sf%\n"; } } if (!safeEquals(originalTicket.getVersion(), updatedTicket.getVersion())) { if (originalTicket.getVersion() == null) { changeNotes += "{version} {setTo} %fs%" + updatedTicket.getVersion() + "%sf%\n"; } else { changeNotes += "{version} %fs%" + originalTicket.getVersion() + "%sf% {changeTo} %fs%" + updatedTicket.getVersion() + "%sf%\n"; } } if (!safeEquals(originalTicket.getAdditionalTime(), updatedTicket.getAdditionalTime())) { if (originalTicket.getAdditionalTime() == null) { changeNotes += "{additionalTime} {setTo} %fs%" + updatedTicket.getAdditionalTime() + "%sf%\n"; } else { changeNotes += "{additionalTime} %fs%" + originalTicket.getAdditionalTime() + "%sf% {changeTo} %fs%" + updatedTicket.getAdditionalTime() + "%sf%\n"; } } if (!safeEqualMuinutes(originalTicket.getPlanedDate(), updatedTicket.getPlanedDate())) { if (originalTicket.getPlanedDate() == null) { changeNotes += "{planedDate} {setTo} %df%{[" + updatedTicket.getPlanedDate().getTime() + "]}%fd%\n"; } else { changeNotes += "{planedDate} {changeTo} %df%{[" + updatedTicket.getPlanedDate().getTime() + "]}%fd%\n"; } } if (!safeEqualMuinutes(originalTicket.getActualDate(), updatedTicket.getActualDate())) { if (originalTicket.getActualDate() == null) { changeNotes += "{actualDate} {setTo} %df%{[" + updatedTicket.getActualDate().getTime() + "]}%fd%\n"; publicChangeNotes += "{actualDate} {setTo} %df%{[" + updatedTicket.getActualDate().getTime() + "]}%fd%\n"; } else { changeNotes += "{actualDate} {changeTo} %df%{[" + updatedTicket.getActualDate().getTime() + "]}%fd%\n"; } } if (!safeEquals(originalTicket.getServiceCode(), updatedTicket.getServiceCode())) { if (originalTicket.getServiceCode() == null) { if (!updatedTicket.getServiceCode().equals("")) changeNotes += "{serviceCode} {setTo} %fs%" + updatedTicket.getServiceCode() + "%sf%\n"; } else { changeNotes += "{serviceCode} {changeTo} %fs%" + updatedTicket.getServiceCode() + "%sf%\n"; } } if (!safeEquals(originalTicket.getPriority(), updatedTicket.getPriority())) { if (originalTicket.getPriority() == null) { if (updatedTicket.getPriority() != null) { changeNotes += "{priority} {setTo} %fs%" + newPriority.getName() + "%sf%\n"; publicChangeNotes += "{priority} {setTo} %fs%" + newPriority.getName() + "%sf%\n"; } } else { changeNotes += "{priority} {changeTo} %fs%" + newPriority.getName() + "%sf%\n"; publicChangeNotes += "{priority} {changeTo} %fs%" + newPriority.getName() + "%sf%\n"; } } if (!safeEquals(originalTicket.getType(), updatedTicket.getType())) { if (originalTicket.getType() == null) { if (updatedTicket.getType() != null) { changeNotes += "{type} {setTo} %fs%" + newType.getName() + "%sf%\n"; } } else { changeNotes += "{type} {changeTo} %fs%" + newType.getName() + "%sf%\n"; } } if (!safeEquals(originalTicket.isChargeable(), updatedTicket.isChargeable())) { if (updatedTicket.isChargeable()) { changeNotes += "%fs%{chargeable}%sf%\n"; } else { changeNotes += " %fs%{notChargeable}%sf%\n"; } } if (!safeEquals(originalTicket.getDescription(), updatedTicket.getDescription())) { if (originalTicket.getDescription() == null) { changeNotes += "%ft%" + updatedTicket.getDescription() + "%tf%\n"; publicChangeNotes += "%ft%" + updatedTicket.getDescription() + "%tf%\n"; } else { changeNotes += " {oldNotes} %ft%" + originalTicket.getDescription() + "%tf%\n"; publicChangeNotes += " {oldNotes} %ft%" + originalTicket.getDescription() + "%tf%\n"; } } if (!safeEquals(originalTicket.getAcceptedNotes(), updatedTicket.getAcceptedNotes())) { if (originalTicket.getAcceptedNotes() == null) { changeNotes += "%ft%" + updatedTicket.getAcceptedNotes() + "%tf%\n"; publicChangeNotes += "%ft%" + updatedTicket.getAcceptedNotes() + "%tf%\n"; } else { changeNotes += "%ft%" + updatedTicket.getAcceptedNotes() + "%tf%\n"; publicChangeNotes += "%ft%" + updatedTicket.getAcceptedNotes() + "%tf%\n"; } } if (!safeEquals(originalTicket.getResolution(), updatedTicket.getResolution())) { if (originalTicket.getResolution() == null) { changeNotes += "%fs%" + updatedTicket.getResolution() + "%sf%\n"; publicChangeNotes += "%fs%" + updatedTicket.getResolution() + "%sf%\n"; } else { changeNotes += " %fs%" + updatedTicket.getResolution() + "%sf%\n"; publicChangeNotes += "%fs%" + updatedTicket.getResolution() + "%sf%\n"; } } if (!safeEquals(originalTicket.getAssignedTo(), updatedTicket.getAssignedTo())) { updatedTicket.setAssignedDate(new Date()); Person person2 = null; try { person2 = (Person) sess.get(Person.class, updatedTicket.getAssignedTo()); } catch (Exception ex) { person2 = new Person(); person2.setName("{empty}"); } changeNotes = "%hb%{taskAssigned} {assignTo} %fs%" + person2.getName() + "%sf% %df%{[" + updatedTicket.getAssignedDate().getTime() + "]}%fd%%bh% %dt%" + changeNotes + "%td%"; // publicChangeNotes += // "%hb%{taskAssigned} {assignTo} %fs%"+person2.getName()+"%sf% %df%{["+updatedTicket.getAssignedDate().getTime()+"]}%fd%%bh% %dt%"+changeNotes+"%td%"; } else if (!changeNotes.trim().equals("")) { changeNotes = "%dt%" + changeNotes + "%td%"; if (!publicChangeNotes.trim().equals("")) { publicChangeNotes = "%dt%" + publicChangeNotes + "%td%"; } } ret[0] = changeNotes; ret[1] = publicChangeNotes; return ret; }
From source file:lt.bsprendimai.ddesk.ChangeDetector.java
License:Apache License
/** * <pre>//from w w w. j av a 2 s .co m * Create a ticket history and change entry for ticket change. * * This method populates TicketHistory object with changes and values from changed ticket. * Fetches the unchanged Ticket from the database and does the comparison. * * Prepends {taskChange} to the changeNotes * * Should be called when a Ticket is changed in all cases, except for Accept, Comment, Close and * ReOpen * </pre> * * See {@link ChangeDetector#preAccept(Ticket)}, * {@link ChangeDetector#preComment(Ticket, String, boolean)}, * {@link ChangeDetector#preClose(Ticket)} and {@link ChangeDetector#preReopen(Ticket)} * * @param updatedTicket * the changed ticket * @return TicketHistory object populated with changed values and detected changes */ public TicketHistory preUpdate(Ticket updatedTicket) { String changeNotes; String publicChangeNotes; Session sess = SessionHolder.currentSession().getSess(); sess.evict(updatedTicket); Ticket originalTicket = (Ticket) sess.get(Ticket.class, updatedTicket.getId()); if (originalTicket == null) { return copyTicket(updatedTicket); } sess.evict(originalTicket); Person person = null; try { person = (Person) sess.get(Person.class, updatedTicket.getEditBy()); } catch (Exception ex) { person = new Person(); person.setName("{empty}"); } String[] changes = this.detectChanges(updatedTicket, originalTicket, person); changeNotes = changes[0]; publicChangeNotes = changes[1]; TicketHistory th = null; if (!changeNotes.equals("")) { changeNotes = "%hb%{taskChange} %fs%" + person.getName() + "%sf% %df%{[" + updatedTicket.getEditDate().getTime() + "]}%fd%%bh%" + changeNotes; th = copyTicket(updatedTicket); th.setChangeNotes(changeNotes); if (!publicChangeNotes.trim().equals("")) { publicChangeNotes = " %hb%{taskChange} %df%{[" + updatedTicket.getEditDate().getTime() + "]}%fd%%bh%" + publicChangeNotes; th.setNotesPublic(publicChangeNotes); } else { th.setNotesPublic(null); } } return th; }