Null value was assigned to a property of primitive type setter of com.superm

Exception:
org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.seven.domain.Book.printTime

原因:数据库里printTime字段为NULL

Java代码
  1.   
  2. "printTime" type="long">"print_time"/>  
[java] view plain copy print ?
  1.   
  2. "printTime" type="long">"print_time"/>  


其中的类型为hibernate类型,在生成的Book类中,printTime字段为long类型,为基本类型,不能为NULL.
解决方法:
    第一种:数据库字段不设置为空;
    第二种:手动修改映射文件,printTime使用Java类型Long,即type="java.lang.Long",Book类中的字段也要改为Long。同理,int为Integer.
    第三种:在反向工程时使用Java类型,而不是hibernate类型。

你可能感兴趣的:(Java)