在使用 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);
}