hibernate hql语句使用1

public void delete(Integer id){
String hql = “DELETE FROM Employee e WHERE e.id = ?”;
getSession().createQuery(hql).setInteger(0, id).executeUpdate();
}

public List getAll(){
String hql = “FROM Employee e LEFT OUTER JOIN FETCH e.department”;
return getSession().createQuery(hql).list();
}

public void saveOrUpdate(Employee employee){
//saveOrUpadate(Object);是一个可以直接调用的方法
getSession().saveOrUpdate(employee);
}

public Employee getEmployeeByLastName(String lastName){
String hql = “FROM Employee e WHERE e.lastName = ?”;
Query query = getSession().createQuery(hql).setString(0, lastName);
Employee employee = (Employee) query.uniqueResult();
System.out.println(employee.getDepartment().getClass().getName());
return employee;
}

public Employee get(Integer id){
return (Employee) getSession().get(Employee.class, id);
}

你可能感兴趣的:(hibernate)