Hibernate:java.lang.Integer和int之间有什么区别?

时间:2011-11-14 01:50:47

标签: hibernate

之间是否存在明显差异
<property name="pwdRetryCount" type="java.lang.Integer">
    <column name="pwd_retry_count" />
</property>

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

1 个答案:

答案 0 :(得分:9)

它们在处理空值时只有明显的区别。

这是因为int是原始数据类型,无法为其分配null,而java.lang.Integerint的包装类,可以接受null。

因此,如果pwd_retry_count列可以为空并且您使用int来映射您的实体对象,则对于pwd_retry_count为空的记录,由于int无法存储而发生错误空。