@Override public Organization update(Organization organization) { Session session = null; Transaction transaction = null; Organization organizationOld = null; try { session = sessionFactory.openSession(); transaction = session.beginTransaction(); organizationOld = (Organization) session.get(Organization.class, organization.getId()); if (organizationOld == null) { throw new HibernateException("can't find organization with id = " + organization.getId()); } if (organization.getDescription() != null) { organizationOld.setDescription(organization.getDescription()); } if (organization.getName() != null) { organizationOld.setName(organization.getName()); } if (organization.getAddress() != null) { Address address = new Address( organization.getAddress().getStreet(), organization.getAddress().getCity(), organization.getAddress().getState(), organization.getAddress().getZip()); organizationOld.setAddress(address); } session.update(organizationOld); transaction.commit(); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } } finally { if (session != null) { session.close(); } } return organizationOld; }
@RequestMapping(value = "/org/{orgId}", method = RequestMethod.GET) public String getOrg(@PathVariable int orgId, Model model) { Organization org = orgService.findByOrgId(orgId); if (org == null) { throw new ResourceNotFoundException(); } model.addAttribute("id", org.getId()); model.addAttribute("name", org.getName()); model.addAttribute("description", org.getDescription()); model.addAttribute("address", org.getAddress()); return "organization"; }