我正在研究 Hibernate 3.3。最近我开始使用标准。我的注释类如下..
@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;
}
}
我的标准代码如下
Criteria criteria=session.createCriteria(Adminlogin.class);
criteria=criteria.add(Restrictions.eq("username", "admin"));
List list=criteria.list();
当 isEnabled 值在一行上为空时,此代码显示错误。我知道它不能将 null 值转换为 long 原始数据类型。所以我想知道有没有其他方法可以跳过任何属性的空值。(我发布了一个表类,并且我有更多具有相同类映射的表)