在使用 spring + Hibernate + JPA 连接 Mysql时,报错如下:
bug:Field 'id' doesn't have a default value
原因是因为自己粗心,主键id并没有自增,没有勾选:AUTO_INCREMENT
代码:
public static void main(String[] args) {
ApplicationContext factory=new ClassPathXmlApplicationContext("classpath:beans.xml");
RequestLogService service = (RequestLogService)factory.getBean("requeLogService");
RequestLog entity = new RequestLog();
entity.setQueryId(21);
entity.setType("212");
entity.setcTime(new Timestamp(System.currentTimeMillis()));
service.save(entity);
}
解决Mysql主键未自增问题
本文介绍了一个常见的Spring+Hibernate+JPA连接Mysql的问题:主键'id'未设置自增导致的错误,并提供了相应的解决方案。通过检查数据库字段设置并确保主键具有自增属性可以解决此问题。
579

被折叠的 条评论
为什么被折叠?



