[英]Hibernate returns null for an integer after getting the data from db in Java
Class
{
private int objectId;
}
<result property="objectId" column="id" />
SQL MAP SQL映射
Query returns null and the int field is set to null. 查询返回null,并且int字段设置为null。 so this line of code 所以这行代码
object.getObjectId();
throws a null pointer exception. 抛出一个空指针异常。
How do i check if objectId is null or not? 如何检查objectId是否为null? I see people using ResultSet in java, but i cannot 我看到人们在Java中使用ResultSet,但是我不能
Change the type from int
to Integer
. 将类型从int
更改为Integer
。 Then it'll be able to be null
, and you'll be able to check this at runtime. 然后它将可以为null
,并且您可以在运行时进行检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.