whether using primitive or wrapper type of fieds defined in entity as per your data model and DB side. if the corresponding column in DB allows null, you should use wrapper type like Short, Integer and Long instead of short, int and long, to avoid NullPointerException occurs.
Specifically, if you have a private int age in your entity;
public setAge(int age){
this.age = age;
}
and this field has a column in DB allows null, thus if search from DB, null cannot be transformed to a primitive data, thus will get NullPointerException.
So use wrapper type instead.