异常1:Exception in thread "main" org.hibernate.HibernateException: Unable to get the default Bean Validation factory
在hibernate.cfg.xml添加属性:<property name="javax.persistence.validation.mode">none</property>
异常2:若是一直是Caused by: java.sql.BatchUpdateException: Table 'hibernate.teacher' doesn't exist
可以添加一条属性:在hibernate.cfg.xml <property name="hbm2ddl.auto">create</property>
异常3:在hibernate+mysql:Field 'id' doesn't have a default value解决办法
使用注解@GeneratorValue,后台报错Field 'id' doesn't have a default value。
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
这是因为在数据库建表时,没有把id设置成自增。需要在数据库字段设置中,将id字段设置自动增加。