且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Hibernate:java.lang.Integer和int之间的区别?

更新时间:2023-02-18 22:14:33

处理空值时它们只有明显的区别。 / p>

这是因为 int 是原始数据类型,当 java时不能为其指定null .lang.Integer int 的包装类,它可以接受null。



因此,如果 pwd_retry_count 列可以为空,并且使用 int 来映射实体对象,那么 pwd_retry_count 为空,错误发生为 int 不能存储null。


Is there any noticeable difference between

<property name="pwdRetryCount" type="java.lang.Integer">
    <column name="pwd_retry_count" />
</property>

and

<property name="pwdRetryCount" type="int">
    <column name="pwd_retry_count" />
</property>

They only have noticeable difference when handling null value.

It is because int is the primitive data type that cannot assign null to it while java.lang.Integer is the wrapper class of int which can accept null .

So , if pwd_retry_count column is nullable and you use int to map your entity object , for the record which pwd_retry_count is null , error occurs as int cannot store null.