问题
I'am working on Hibernate 3.3. Recently I started using criteria. My Annotation class is as follows..
@Entity
@Table(name = "EMAG_ADMINLOGIN", schema = "EMAG_USER")
public class Adminlogin implements java.io.Serializable {
private String username;
private String password;
private String fullname;
private long isenabled;
@Id
@Column(name = "USERNAME", unique = true, nullable = false, length = 40)
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name = "PASSWORD", length = 40)
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name = "FULLNAME", nullable = false, length = 100)
public String getFullname() {
return this.fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
@Column(name = "ISENABLED", precision = 0)
public long getIsenabled() {
return this.isenabled;
}
public void setIsenabled(long isenabled) {
this.isenabled = isenabled;
}
}
And my criteria code is as follows
Criteria criteria=session.createCriteria(Adminlogin.class);
criteria=criteria.add(Restrictions.eq("username", "admin"));
List list=criteria.list();
this code showing error when isEnabled value is null on a row. I know it can not convert null value to primitive data type long. So I want to know is there any other way to skip null value of any property . (I posted one table class, and i have more tables with same kind of class mappings)
回答1:
Change type of 'isenabled' to 'Long' or have default value defined for the column in db schema based on your requirements.
回答2:
Try to Use the NotFound annotation: may be your problem will be solved
@NotFound(action = NotFoundAction.IGNORE)
来源:https://stackoverflow.com/questions/15043866/criteria-list-shows-null-pointer-exception