我的entity文件是这样的
@Entity @Table(name = "userinfo", schema = "designerdb", catalog = "") public class UserinfoEntity { @Id @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") @Column(length=32,nullable = false) private String userid; @Column(length=25) private String username; @Column(length=25) private String password; @Column(length=25) private String realname; @Column(length=2) private String sex; @Column(length=3) private Integer age; @Column(length=18) private String idnumber; @Column(length=11) private String telephone; @Column(length=100) private String emailAddress; @Column(length=25) private String phone; @Column(length=100) private String workPlace;
最后就是报错
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.springapp.model.UserinfoEntity org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868) javax.servlet.http.HttpServlet.service(HttpServlet.java:648) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:231) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
我的controller是这样写的
因为我要做的是用户注册的功能,所以主键要自动生成,我前台表单没有userid值,本身就是想后台能自动生成ID的
那问题这不是很明显,你的userid字段设置了nullable=fase,也就是说保存的时候userid必须要不为空,然后userid不是从前台传过来的,你也没手动set进去啊,版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。