Why do I get a “Null value was assigned to a property of primitive type setter of” error message when using HibernateCriteriaBuilder in Grails

后端 未结 12 678
长情又很酷
长情又很酷 2021-01-30 07:58

I get the following error when using a primitive attribute in my grails domain object:

Null value was assigned to a property of primitive type setter of MyDomain         


        
12条回答
  •  孤独总比滥情好
    2021-01-30 08:21

    Change the parameter type from primitive to Object and put a null check in the setter. See example below

    public void setPhoneNumber(Long phoneNumber) {
        if (phoneNumber != null)
            this.phoneNumber = phoneNumber;
        else
            this.extension = 0l;
    }
    

提交回复
热议问题