Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.myAttribute  org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of MyDomain.myAttribute at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1077) 
like image 837
Peter Avatar asked Jul 01 '10 01:07

Peter


People also ask

Why do I get a null value was assigned to a property of primitive type setter of?

A primitive is not an Object, therefore u can't assign null to it.

Can a primitive type be null?

Java primitive types (such as int , double , or float ) cannot have null values, which you must consider in choosing your result expression and host expression types.

How do you set a Boolean value to null in Java?

You could use a string instead of boolean and set it to "False", "True" or "" where the empty string represents your null value. Alternatively you need for every Boolean an extra Boolean like <attribute>IsSpecified which you set to false if the attribute value false means null.


1 Answers

According to this SO thread, the solution is to use the non-primitive wrapper types; e.g., Integer instead of int.

like image 181
Peter Avatar answered Sep 17 '22 13:09

Peter