我有一個spring spring MVC 3.0應用程序,實現了spring security。我正在創建一個小彈出窗口來更改當前登錄用戶的密碼。一切都很好,直到我將表單發佈到以下操作。更改密碼 - Spring Security
@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
我在做什麼錯?
你能描述一下方法嗎principal.merge? – Jhonathan 2012-07-17 15:03:36
合併用於已存在的實體,即已存儲在數據庫中。如果它是一個全新的校長,我會說principal.persist(); – Binaryrespawn 2012-07-17 15:25:30