我有一个实现了 spring 安全性的 spring MVC 3.0 应用程序。我正在创建一个小弹出窗口来更改当前登录用户的密码。一切都很好,直到我将表单发布到以下操作。
@RequestMapping(value = "principalchangepassword" , method = RequestMethod.POST)
public @ResponseBody String principalchangepassword(Model uiModel, HttpServletRequest httpServletRequest){
Principal principal = (Principal) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
StandardStringDigester digester = new StandardStringDigester();
digester.setAlgorithm("SHA-256"); // optionally set the algorithm
digester.setStringOutputType("hexadecimal");
digester.setSaltSizeBytes(0);
digester.setIterations(1);
String digest = digester.digest(httpServletRequest.getParameter("password1"));
principal.setPassword(digest.toLowerCase());
principal.merge();
return "Password Updated successfully";
}
当我执行 ajax 调用以更新当前主体的密码时,我收到以下异常消息。
org.hibernate.TransientObjectException: object references an unsaved transient instance – save the transient instance before flushing
我究竟做错了什么 ?