zoukankan      html  css  js  c++  java
  • Null value was assigned to a property of primitive type setter of"原因及解决方法

    原文:http://blog.csdn.net/kevinzhangfei/article/details/6995316

    总结:在Java中使用大写的数据类型。

    在action请求数据的过程中报出"Null value was assigned to a property of primitive type setter of"错误,搜索之后发现是因为数据库里相应的字段为NULL。

    例如:

    Java代码  

    <!--Hibernate映射文件中的字段--> 

    <property name="printTime" type="long"><column name="print_time"/></property> 

    [java] view plain copy
     
     print?
    1. <!--Hibernate映射文件中的字段-->  
    2. <property name="printTime" type="long"><column name="print_time"/></property>  

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

  • 相关阅读:
    HDU What Are You Talking About
    谷歌面试题
    POJ 2299 UltraQuickSort
    单链表排序
    HDU Hat’s Words
    C++ const关键字
    求二叉树任意两点间的距离
    HDU Phone List
    POJ 2352 Stars
    C++ volatile关键字
  • 原文地址:https://www.cnblogs.com/luodengxiong/p/5364768.html
Copyright © 2011-2022 走看看