美好的一天。我有DAO方法删除一些文件。
@Override
public void deleteFormDescription(Date formDate, String institutionName) {
Session session = sessionFactory.getCurrentSession();
Integer dateId = fetchDateId(formDate);
Integer institutionId = fetchInstitutionId(institutionName);
if(dateId == null && institutionId == null) {
throw new UnexpectedRollbackException("Transaction will roll back because, dateId: " + dateId + " and institutionId: " + institutionId);
}
try {
FormDescription formDescription = (FormDescription)session.createCriteria(FormDescription.class, "formDescription")
.createAlias("formDescription.institutions", "institution").add(Restrictions.eq("institution.institutionId", institutionId))
.createAlias("formDescription.formDate", "formDate").add(Restrictions.eq("formDate.dateId", dateId)).uniqueResult();
session.delete(formDescription);
session.flush();
} catch(RuntimeException e) {
throw new UnexpectedRollbackException("Transaction will roll back because " +
" method deleteFormDescription(Date formDate, String institutionName) could not delete an FormDescription");
}
}
在我的控制器中,我有:
@RequestMapping(value="/deleteprocessing", method=RequestMethod.GET)
public String deleteProcessing(@RequestParam String particularDate,
@RequestParam String institutionName) throws Exception {
educationWebService.deleteFormDescriptionService(dateConvertation(particularDate), institutionName);
return "redirect:/delete";
}
我需要在JSP页面上渲染这个方法,并将其删除。是否有可能做到这一点?谢谢你们。
答案 0 :(得分:1)
当然有可能。删除后,保留已删除的FormDescription实体对象的分离的实例,并将其传递给JSP进行显示。
请记住,一旦事务提交并且Hibernate会话关闭,您的实体对象(应该)处于分离状态。