无法将int字段设置为空值

时间:2018-08-05 19:13:28

标签: java hibernate spring-data-jpa

我有此int列:

@Column(length = 4)
private int contract_owner_id;

我不需要为每个表行设置始终值。当我进行选择查询时,我得到了这个异常:

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

当表列中没有数据时,是否有某种方法可以设置麻木的设置?

2 个答案:

答案 0 :(得分:6)

原始数据类型 int 不是可空。在这种情况下,您需要使用包装程序类“ Integer”。因此,只需替换类型即可。

答案 1 :(得分:0)

使用Integer代替int

ex-:

private Integer contract_owner_id;

相关问题