Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not set int field to null value

I have this int column:

@Column(length = 4)
private int contract_owner_id;

I don't need to set always value for every table row. I get this exception when I make select query:

Can not set int field org.entity.contracts.contract_owner_id to null value

Is there some way to set numb setups when there is no data into the table column?

like image 695
Peter Penzov Avatar asked Aug 05 '18 19:08

Peter Penzov


People also ask

Can you set an int to 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.

Can int be set to null C++?

Unlike for pointers, there is no distinct "nulL" value for integers. Given that, your only choice is to store some extra information indicating whether a meaningful value is stored or not.

Can you initialize an int to null in C?

In C, a null pointer constant must be an integer literal with the value 0, or the same cast to type "pointer to void"1. An integer with a non-zero value (by itself, or cast to type "pointer to void") is not allowed2. So, 0 , 0L and ((void *)0) are all allowed, but something like ((void *)1234) is not.


1 Answers

The primitive datatype int isn't nullable. You need to use the Wrapper class "Integer" in this case. So just replace the type.

like image 100
Kikkirej Avatar answered Sep 30 '22 18:09

Kikkirej