List of usage examples for org.hibernate Session evict
void evict(Object object);
From source file:org.jasig.ssp.dao.PersonProgramStatusDaoTest.java
License:Apache License
/** * Test {@link PersonProgramStatusDao#save(PersonProgramStatus)} , * {@link PersonProgramStatusDao#get(UUID)}, * {@link PersonProgramStatusDao#getAll(ObjectStatus)}, and * {@link PersonProgramStatusDao#delete(PersonProgramStatus)}. * //from www . j a va 2 s .co m * @throws ObjectNotFoundException * If saved instance could not be reloaded. */ @Test public void testSaveNew() throws ObjectNotFoundException { UUID saved; PersonProgramStatus obj = new PersonProgramStatus(); obj.setObjectStatus(ObjectStatus.ACTIVE); obj.setPerson(securityService.currentUser().getPerson()); obj.setProgramStatus(programStatusDao.get(UUID.fromString("b2d12527-5056-a51a-8054-113116baab88"))); obj.setProgramStatusChangeReason( programStatusChangeReasonDao.get(UUID.fromString("b2d128f0-5056-a51a-803f-8cef57177aea"))); obj.setEffectiveDate(new Date()); obj = dao.save(obj); assertNotNull("Saved object should not have been null.", obj.getId()); saved = obj.getId(); // flush to storage, then clear out in-memory version final Session session = sessionFactory.getCurrentSession(); session.flush(); session.evict(obj); obj = dao.get(saved); LOGGER.debug("testSaveNew(): Saved " + obj.toString()); assertNotNull("Reloaded object should not have been null.", obj); assertNotNull("Reloaded ID should not have been null.", obj.getId()); final List<PersonProgramStatus> all = (List<PersonProgramStatus>) dao.getAll(ObjectStatus.ACTIVE).getRows(); assertNotNull("GetAll list should not have been null.", all); assertFalse("GetAll list should not have been empty.", all.isEmpty()); assertList(all); dao.delete(obj); }
From source file:org.jasig.ssp.dao.PersonReferralSourceDaoTest.java
License:Apache License
/** * Test {@link PersonReferralSourceDao#save(PersonReferralSource)} , * {@link PersonReferralSourceDao#get(UUID)}, * {@link PersonReferralSourceDao#getAll(ObjectStatus)}, and * {@link PersonReferralSourceDao#delete(PersonReferralSource)}. * /*from w ww . j a v a2 s .c o m*/ * @throws ObjectNotFoundException * If saved instance could not be reloaded. */ @Test public void testSaveNew() throws ObjectNotFoundException { UUID saved; PersonReferralSource obj = new PersonReferralSource(); obj.setObjectStatus(ObjectStatus.ACTIVE); obj.setPerson(securityService.currentUser().getPerson()); obj.setReferralSource(referralSourceDao.get(UUID.fromString("f6201a04-bb31-4ca5-b606-609f3ad09f87"))); obj = dao.save(obj); assertNotNull("Saved object should not have been null.", obj.getId()); saved = obj.getId(); // flush to storage, then clear out in-memory version final Session session = sessionFactory.getCurrentSession(); session.flush(); session.evict(obj); obj = dao.get(saved); LOGGER.debug("testSaveNew(): Saved " + obj.toString()); assertNotNull("Reloaded object should not have been null.", obj); assertNotNull("Reloaded ID should not have been null.", obj.getId()); final List<PersonReferralSource> all = (List<PersonReferralSource>) dao.getAll(ObjectStatus.ACTIVE) .getRows(); assertNotNull("GetAll list should not have been null.", all); assertFalse("GetAll list should not have been empty.", all.isEmpty()); assertList(all); dao.delete(obj); }
From source file:org.jasig.ssp.dao.PersonServiceReasonDaoTest.java
License:Apache License
/** * Test {@link PersonServiceReasonDao#save(PersonServiceReason)} , * {@link PersonServiceReasonDao#get(UUID)}, * {@link PersonServiceReasonDao#getAll(ObjectStatus)}, and * {@link PersonServiceReasonDao#delete(PersonServiceReason)}. * //from w w w .ja va2 s .c o m * @throws ObjectNotFoundException * If saved instance could not be reloaded. */ @Test public void testSaveNew() throws ObjectNotFoundException { UUID saved; PersonServiceReason obj = new PersonServiceReason(); obj.setObjectStatus(ObjectStatus.ACTIVE); obj.setPerson(securityService.currentUser().getPerson()); obj.setServiceReason(serviceReasonDao.get(UUID.fromString("f6201a04-bb31-4ca5-b606-609f3ad09f87"))); obj = dao.save(obj); assertNotNull("Saved object should not have been null.", obj.getId()); saved = obj.getId(); // flush to storage, then clear out in-memory version final Session session = sessionFactory.getCurrentSession(); session.flush(); session.evict(obj); obj = dao.get(saved); LOGGER.debug("testSaveNew(): Saved " + obj.toString()); assertNotNull("Reloaded object should not have been null.", obj); assertNotNull("Reloaded ID should not have been null.", obj.getId()); final List<PersonServiceReason> all = (List<PersonServiceReason>) dao.getAll(ObjectStatus.ACTIVE).getRows(); assertNotNull("GetAll list should not have been null.", all); assertFalse("GetAll list should not have been empty.", all.isEmpty()); assertList(all); dao.delete(obj); }
From source file:org.jasig.ssp.dao.PersonSpecialServiceGroupDaoTest.java
License:Apache License
/** * Test {@link PersonSpecialServiceGroupDao#save(PersonSpecialServiceGroup)} * , {@link PersonSpecialServiceGroupDao#get(UUID)}, * {@link PersonSpecialServiceGroupDao#getAll(ObjectStatus)}, and * {@link PersonSpecialServiceGroupDao#delete(PersonSpecialServiceGroup)}. * /*w w w . ja va 2 s. co m*/ * @throws ObjectNotFoundException * If saved instance could not be reloaded. */ @Test public void testSaveNew() throws ObjectNotFoundException { UUID saved; PersonSpecialServiceGroup obj = new PersonSpecialServiceGroup(); obj.setObjectStatus(ObjectStatus.ACTIVE); obj.setPerson(securityService.currentUser().getPerson()); obj.setSpecialServiceGroup( specialServiceGroupDao.get(UUID.fromString("f6201a04-bb31-4ca5-b606-609f3ad09f87"))); obj = dao.save(obj); assertNotNull("Saved object should not have been null.", obj.getId()); saved = obj.getId(); // flush to storage, then clear out in-memory version final Session session = sessionFactory.getCurrentSession(); session.flush(); session.evict(obj); obj = dao.get(saved); LOGGER.debug("testSaveNew(): Saved " + obj.toString()); assertNotNull("Reloaded object should not have been null.", obj); assertNotNull("Reloaded ID should not have been null.", obj.getId()); final List<PersonSpecialServiceGroup> all = (List<PersonSpecialServiceGroup>) dao .getAll(ObjectStatus.ACTIVE).getRows(); assertNotNull("GetAll list should not have been null.", all); assertFalse("GetAll list should not have been empty.", all.isEmpty()); assertList(all); dao.delete(obj); }
From source file:org.jasig.ssp.web.api.PersonEarlyAlertControllerIntegrationTest.java
License:Apache License
/** * Test that student->coach is set during EarlyAlert creation. * //from www . j av a 2 s. co m * <p> * This test assumes that the default campus EA coordinator is the system * administrator account. * * @throws ValidationException * If validation error occurred. * @throws ObjectNotFoundException * If object could not be found. */ @Test public void testControllerCreateAndSetCoach() throws ObjectNotFoundException, ValidationException { final Session session = sessionFactory.getCurrentSession(); final EarlyAlertTO obj = createEarlyAlert(); final UUID studentId = obj.getPersonId(); final Person student = personService.get(studentId); student.setCoach(null); assertNull("Test data coach should have been null.", student.getCoach()); session.flush(); assertNull("Student coach should have been null.", student.getCoach()); // No that coach has been cleared, save EarlyAlert to ensure it is reset final EarlyAlertTO saved = controller.create(studentId, obj); assertNotNull("Saved Early Alert should not have been null.", saved); session.flush(); assertNotNull("Student coach should not have been null.", student.getCoach()); session.evict(student); final Person reloadedPerson = personService.get(studentId); assertEquals("Coach IDs did not match.", Person.SYSTEM_ADMINISTRATOR_ID, reloadedPerson.getCoach().getId()); }
From source file:org.javamexico.dao.hib3.UsuarioDAO.java
License:Open Source License
public void update(Usuario u) { Session sess = sfact.getCurrentSession(); Usuario u2 = (Usuario) sess.get(Usuario.class, u.getUid()); if (u2.getPassword() == null || !u2.getPassword().equals(u.getPassword())) { u.setPassword(cifraPassword(u.getPassword(), u.getUsername(), u.getUid())); }/*from w ww . j a v a 2s. co m*/ sess.evict(u2); sess.update(u); }
From source file:org.jtalks.poulpe.model.dao.hibernate.ObjectRetriever.java
License:Open Source License
/** * Retrieves the actual object stored in the database, clearing session's * cache for ensuring the object is brand new.<br> * //from w w w .j a v a 2 s .co m * The old object is needed here for 1) evicting it from cache 2) getting * its id for retrieving.<br> * <br> * * <b>Example of usage:</b><br> * * 1) Retrieving the branch * * <pre> * private PoulpeBranch retrieveActualBranch() { * return ObjectRetriever.retrieveUpdated(branch, session); * } * </pre> * * 2) Retrieving the section: * * <pre> * private PoulpeSection retrieveActualSection() { * return ObjectRetriever.retrieveUpdated(section, session); * } * </pre> * * * @param object to retrieve * @param session Hibernate session * @return brand new retrieved object from the database */ public static <E extends Entity> E retrieveUpdated(E object, Session session) { session.evict(object); return retrieve(object, session); }
From source file:org.kemri.wellcome.dhisreport.api.db.hibernate.HibernateDHIS2ReportingDAO.java
License:Open Source License
public Identifiable saveObject(Identifiable object) { Session session = entityManager.unwrap(Session.class); // force merge if uid already exists Identifiable existingObject = getObjectByUid(object.getUid(), object.getClass()); // force merge if name already exists but replace uid Identifiable existingObject2 = getObjectByName(object.getName(), object.getClass()); String uid = object.getUid(); if (existingObject != null) { session.evict(existingObject); object.setId(existingObject.getId()); session.load(object, object.getId()); } else if (existingObject == null && existingObject2 != null) { session.evict(existingObject2);/*from ww w .jav a2 s.c o m*/ object.setId(existingObject2.getId()); session.load(object, object.getId()); } object.setUid(uid); session.saveOrUpdate(object); return object; }
From source file:org.meveo.grieg.dunning.task.ValidatedDunningProcessorTask.java
License:Open Source License
/** * Save GriegDunningInputHistory with results of input processing. * /* ww w .jav a 2 s . c o m*/ * @param taskExecution * Processing context object that holds all information how did. */ @Override protected void persistInputHistory(TaskExecution<GriegTicket> taskExecution) { try { String inputName = taskExecution.getInputObject().getName(); if (logger.isDebugEnabled()) { logger.debug(String.format("Updating GriegDunningInputHistory entity for source %s", inputName)); } InputHistory inputHistory = taskExecution.getInputHistory(); Long inputHistoryId = inputHistory.getId(); EntityManager em = MeveoPersistence.getEntityManager(); org.hibernate.Session session = (Session) em.getDelegate(); session.evict(inputHistory); session.createQuery("update InputHistory set INPUT_TYPE = :newType where id = :id") .setString("newType", "GRIEG_DUNNING").setLong("id", inputHistoryId).executeUpdate(); GriegDunningInputHistory dunningInputHistory = em.find(GriegDunningInputHistory.class, inputHistoryId); dunningInputHistory.setName(inputName); dunningInputHistory.setAnalysisStartDate(taskExecution.getStartTime()); dunningInputHistory.setAnalysisEndDate(taskExecution.getEndTime()); dunningInputHistory.setParsedTickets(taskExecution.getParsedTicketsCount()); dunningInputHistory.setRejectedTickets(taskExecution.getRejectedTicketsCount()); dunningInputHistory.setSucceededTickets(taskExecution.getProcessedTicketsCount()); dunningInputHistory.setProvider(taskExecution.getProvider()); em.merge(dunningInputHistory); if (logger.isDebugEnabled()) { logger.debug(String.format( "Inserting GriegDunningInputHistory entity for source %s completed successfuly", inputName)); } } catch (Exception e) { logger.error("Could not save batch process ", e); } }
From source file:org.meveo.grieg.invoiceConverter.task.InvoiceConverterTask.java
License:Open Source License
/** * Save GriegInvoiceConverterInputHistory with results of input processing. * /*from w w w . j ava2 s. c o m*/ * @param taskExecution * Processing context object that holds all information how did. */ @Override protected void persistInputHistory(TaskExecution<GriegTicket> taskExecution) { try { String inputName = taskExecution.getInputObject().getName(); if (logger.isDebugEnabled()) { logger.debug(String.format("Updating GriegInvoiceConverterInputHistory entity for source %s", inputName)); } InputHistory inputHistory = taskExecution.getInputHistory(); Long inputHistoryId = inputHistory.getId(); EntityManager em = MeveoPersistence.getEntityManager(); org.hibernate.Session session = (Session) em.getDelegate(); session.evict(inputHistory); session.createQuery("update InputHistory set INPUT_TYPE = :newType where id = :id") .setString("newType", "GRIEG_CONVERTER").setLong("id", inputHistoryId).executeUpdate(); GriegInvoiceConverterInputHistory invoiceConverterInputHistory = em .find(GriegInvoiceConverterInputHistory.class, inputHistoryId); invoiceConverterInputHistory.setName(inputName); invoiceConverterInputHistory.setAnalysisStartDate(taskExecution.getStartTime()); invoiceConverterInputHistory.setAnalysisEndDate(taskExecution.getEndTime()); invoiceConverterInputHistory.setParsedTickets(taskExecution.getParsedTicketsCount()); invoiceConverterInputHistory.setRejectedTickets(taskExecution.getRejectedTicketsCount()); invoiceConverterInputHistory.setSucceededTickets(taskExecution.getProcessedTicketsCount()); invoiceConverterInputHistory.setProvider(taskExecution.getProvider()); em.merge(invoiceConverterInputHistory); if (logger.isDebugEnabled()) { logger.debug(String.format( "Inserting GriegInvoiceConverterInputHistory entity for source %s completed successfuly", inputName)); } } catch (Exception e) { logger.error("Could not save batch process ", e); } }