Hibernate:java.lang.Integer和int之间的区别? [英] Hibernate: any difference between java.lang.Integer and int?

查看:135
本文介绍了Hibernate:java.lang.Integer和int之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 < property name =pwdRetryCounttype =java.lang.Integer > 
< column name =pwd_retry_count/>
< / property>

 < property name =pwdRetryCounttype =int> 
< column name =pwd_retry_count/>
< / property>


解决方案

处理空值时它们只有明显的区别。 / 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.

这篇关于Hibernate:java.lang.Integer和int之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆