我使用spring roo構建CMS web應用程序。Spring roo:無法更新由PhpMyAdmin插入的用戶數據
當然這個程序,具有用戶管理功能。
我的問題是,如果我使用phpMyAdmin插入用戶信息到數據庫,則跳轉至我的應用程序修改thoes信息,錯誤orcur。 (如果我插入用戶信息的應用程序和編輯應用程序,它工作正常)
你們誰能給我解釋一下,爲什麼它的發生,以及如何解決它?
非常感謝。
加成信息:此錯誤orcur只能由用戶表,另一個表(如新聞或產品),沒有問題。 以下是我的一些代碼。
EndUser.java(實體)
public class EndUser {
@NotNull
@Size(min = 1, max = 20)
@Column(name = "user_id", unique = true, nullable = false)
private String userId;
@Column(name = "user_name")
private String name;
@NotNull
@Size(min = 1, max = 40)
@Column(name = "password", nullable = false)
private String password;
@Column(name = "first_name")
private String firstName;
@Column(name = "last_name")
private String lastName;
@Column(name = "gender")
private Integer gender;
@Column(name = "email")
private String email;
@Column(name = "last_login")
@DateTimeFormat(style = "M-")
private Date lastLogin;
@Column(name = "created_date")
@DateTimeFormat(style = "M-")
private Date createdDate;
@Column(name = "date_of_birth")
@DateTimeFormat(style = "M-")
private Date dateOfBirth;
@NotNull
@Column(name = "role")
private String role;
@Column(name = "is_deleted")
private Boolean isDeleted;
}
EndUserController.java
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@Valid EndUser endUser, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
populateEditForm(uiModel, endUser);
return "admin/user/update";
}
endUser.setIsDeleted(false);
uiModel.asMap().clear();
endUser.merge();
return "redirect:/admin/user/" + encodeUrlPathSegment(endUser.getId().toString(), httpServletRequest);
}
如果我更新其插入通過phpMyAdmin的,誤差orcur
2013-05-08 20:10:58,741 [http-8080-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Found thread-bound EntityManager [[email protected]] for JPA transaction
2013-05-08 20:10:58,741 [http-8080-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Creating new transaction with name [vn.a2s.lib.db.model.EndUser.merge]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
2013-05-08 20:10:58,741 [http-8080-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Not exposing JPA transaction [[email protected]] as JDBC transaction because JpaDialect [[email protected]] does not support JDBC Connection retrieval
2013-05-08 20:10:58,743 [http-8080-7] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'vn.a2s.lib.db.model.EndUser': PersistenceElement for transient javax.persistence.EntityManager vn.a2s.lib.db.model.EndUser.entityManager
2013-05-08 20:10:58,743 [http-8080-7] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
2013-05-08 20:10:58,752 [http-8080-7] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Duplicate entry 'nghi' for key 'user_id'
2013-05-08 20:10:58,752 [http-8080-7] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Duplicate entry 'nghi' for key 'user_id'
2013-05-08 20:10:58,752 [http-8080-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Initiating transaction rollback
2013-05-08 20:10:58,752 [http-8080-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Rolling back JPA transaction on EntityManager [[email protected]]
2013-05-08 20:10:58,753 [http-8080-7] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Not closing pre-bound JPA EntityManager after transaction
2013-05-08 20:10:58,754 [http-8080-7] DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [public java.lang.String vn.a2s.sparepart.web.admin.EndUserController.update(vn.a2s.lib.db.model.EndUser,org.springframework.validation.BindingResult,org.springframework.ui.Model,javax.servlet.http.HttpServletRequest)]: org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'
2013-05-08 20:10:58,754 [http-8080-7] DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolving exception from handler [public java.lang.String vn.a2s.sparepart.web.admin.EndUserController.update(vn.a2s.lib.db.model.EndUser,org.springframework.validation.BindingResult,org.springframework.ui.Model,javax.servlet.http.HttpServletRequest)]: org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'
2013-05-08 20:10:58,754 [http-8080-7] DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [public java.lang.String vn.a2s.sparepart.web.admin.EndUserController.update(vn.a2s.lib.db.model.EndUser,org.springframework.validation.BindingResult,org.springframework.ui.Model,javax.servlet.http.HttpServletRequest)]: org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'
2013-05-08 20:10:58,754 [http-8080-7] DEBUG org.springframework.web.servlet.handler.SimpleMappingExceptionResolver - Resolving exception from handler [public java.lang.String vn.a2s.sparepart.web.admin.EndUserController.update(vn.a2s.lib.db.model.EndUser,org.springframework.validation.BindingResult,org.springframework.ui.Model,javax.servlet.http.HttpServletRequest)]: org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'
2013-05-08 20:10:58,754 [http-8080-7] DEBUG org.springframework.web.servlet.handler.SimpleMappingExceptionResolver - Resolving to view 'dataAccessFailure' for exception of type [org.springframework.orm.jpa.JpaSystemException], based on exception mapping [.DataAccessException]
2013-05-08 20:10:58,754 [http-8080-7] DEBUG org.springframework.web.servlet.handler.SimpleMappingExceptionResolver - Exposing Exception as model attribute 'exception'
2013-05-08 20:10:58,754 [http-8080-7] DEBUG org.springframework.web.servlet.DispatcherServlet - Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'dataAccessFailure'; model is {exception=org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'}
org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Duplicate entry 'nghi' for key 'user_id'
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:318)
at org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect.ajc$afterThrowing$org_springframework_orm_jpa_aspectj_JpaExceptionTranslatorAspect$1$18a1ac9(JpaExceptionTranslatorAspect.aj:15)
at vn.a2s.lib.db.model.EndUser_Roo_Jpa_ActiveRecord.ajc$interMethod$vn_a2s_lib_db_model_EndUser_Roo_Jpa_ActiveRecord$vn_a2s_lib_db_model_EndUser$merge(EndUser_Roo_Jpa_ActiveRecord.aj:72)
at vn.a2s.lib.db.model.EndUser.merge(EndUser.java:1)
at vn.a2s.lib.db.model.EndUser_Roo_Jpa_ActiveRecord.ajc$interMethodDispatch1$vn_a2s_lib_db_model_EndUser_Roo_Jpa_ActiveRecord$vn_a2s_lib_db_model_EndUser$merge(EndUser_Roo_Jpa_ActiveRecord.aj)
at vn.a2s.sparepart.web.admin.EndUserController.update(EndUserController.java:87)
at vn.a2s.sparepart.web.admin.EndUserController$$FastClassByCGLIB$$ed0ea343.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
at vn.a2s.sparepart.web.admin.EndUserController$$EnhancerByCGLIB$$48aaf78c.update(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:833)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:640)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:74)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
在表格/對象上是否有版本列/字段? – Solubris 2013-05-17 23:36:04
是的,版本字段在EndUser_Roo_Entity.aj中進行管理 – 2013-06-04 03:47:03