0
これは私のVOである:私はcriteria
を使用した後NullPointerException
を取得していますJavaの春/休止状態:criteria.listを使用して上のNullpointException()
。
EmployeeVO.java
@Entity
@Table(name="EMPLOYEES")
public class EmployeeVO {
@Id
@Column(name="employee_id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer employee_id;
private String first_name;
private String last_name;
private String job_id;
private String phone_number;
private Integer salary;
@Column(nullable=true, name="manager_id")
private Integer manager_id;
@Column(nullable=true, name="user_id")
private Integer user_id;
private Integer department_id;
@OneToOne
@JoinColumn(name="department_id", referencedColumnName="department_id", insertable=false, updatable=false)
private DepartmentVO department;
//getters and setters
@Override
public String toString() {
return "EmployeeVO [employee_id=" + employee_id + ", first_name=" + first_name + ", last_name=" + last_name
+ ", job_id=" + job_id + ", phone_number=" + phone_number + ", salary=" + salary + ", manager_id="
+ manager_id + ", user_id=" + user_id + ", department_id=" + department_id + ", department="
+ department + "]";
}
}
DAOImpl:
@Override
public List<EmployeeVO> getEmployeeList(SearchForm searchForm) {
logger.info("SearchForm Detail :: "+searchForm);
Session session = this.sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(EmployeeVO.class);
criteria.setProjection(Projections.projectionList());
if (null != searchForm.getOpt() || !"".equals(searchForm.getOpt())) {
criteria.add(Restrictions.like(searchForm.getOpt(), searchForm.getKeyword()));
}
if (null != searchForm.getMaxSalary()) {
criteria.add(Restrictions.lt("salary", searchForm.getMaxSalary()));
}
if (null != searchForm.getMinSalary()) {
criteria.add(Restrictions.gt("salary", searchForm.getMinSalary()));
}
if (null != searchForm.getOrderBy() || !"".equals(searchForm.getOrderBy())) {
if ("asc".equals(searchForm.getOrderBy())) {
criteria.addOrder(Order.asc(searchForm.getSort()));
} else if ("desc".equals(searchForm.getOrderBy())) {
criteria.addOrder(Order.desc(searchForm.getSort()));
}
}
criteria.setFirstResult((searchForm.getPageNo()-1)*searchForm.getDisplay());
criteria.setMaxResults(searchForm.getDisplay());
List<EmployeeVO> employeeList = criteria.list();
logger.info("Employee List Size :: "+employeeList.size());
return employeeList;
}
criteria.list()は、NullPointException
をスローなぜ誰もが知っていますか?
私はquery.list()を使用しても大丈夫でしたが、基準に変更した後にエラーが発生しました。
https://stackoverflow.com/questions/15043866/criteria-list-shows-null-pointer-exceptionを参照してください。 – user7294900