Float with Spring null value

Asked

Viewed 100 times

0

I have an application with Spring Data. Calling the Spring findAll() method, there are null values in the database. When setting the object the field comes with null value triggering the error message: Can not set float field br.com.pedidosweb.ws.model.Produto.pro_estoqmax to null value.

I’d have some way of treating that?

1 answer

0

From what you described, I have the impression that you have in your class an attribute of the kind float, i.e., a primitive type. In this case, you must be having an exception of type IllegalArgumentException: Can not set float field br.com.pedidosweb.ws.model.Produto.pro_estoqmax to null value.

By this exception? Why the float is a primitive type and does not work or accept null value. Thus, if in the bank its column is null, it would have to receive a value null what is not possible.

To solve, change your attribute to Float or set your column in the database to zero default, so instead of null will be 0.0.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.