简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM