Search code examples
grailsgrails-orm

grails, loading domain from db when fields contains null causes setters to fail


This problem is about some fields that are declared double and often is null in the database. Using findAllBy to receive a list then fails if some of the fields are null. I tried with changing the type to Double but then I get problems when I do arithmetics on them. If the value is null the Double can't decide which converter it should use. I don't know if there is any way to convert nulls in the domain before they are set. Example of error:

Caused by: org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.buffer.ProdBuffer.makeInquiry

Solution

  • You should always use Double in your entities/domains; unless you have a nullable: false constraint at work, even then it's a good practice, nonetheless.

    However, you need to handle null by yourself in your calculations, probably by making that 0 or 1, you know it better. For more suggestions, post the code snippet.