9
votes

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?

2
Can you change int to Integer or Long please - YCF_L
Wha tis the difference in int and Integer when I use them with JPA? - Peter Penzov
int is a primitive type not an Object - YCF_L
Though int and Integer are used to store integer type data the major difference between both is type of int is primitive while Integer is of class type. So int can not be null. - Anupama Karunarathna

2 Answers

31
votes

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

2
votes

use Integer instead of int

ex-:

private Integer contract_owner_id;