现在的位置: 首页 > 综合 > 正文

学习hibernate 所遇到的一些Exception

2018年05月23日 ⁄ 综合 ⁄ 共 734字 ⁄ 字号 评论关闭
文章目录

异常1:Exception in thread "main" org.hibernate.HibernateException: Unable to get the default Bean Validation factory

 

javax.persistence.validation.mode默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个bean-validation**包,但是找不到,所以beanvalitionFactory错误。

 

在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字段设置自动增加。

 

抱歉!评论已关闭.