Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用hibernate选择数据?_Hibernate - Fatal编程技术网

如何使用hibernate选择数据?

如何使用hibernate选择数据?,hibernate,Hibernate,我正在使用SpringMVC和Hibernate。我使用Hibernate编写insert,但找不到从数据库中写入搜索数据的方法。我在下面的例子中插入了一个我喜欢的过程。如何使用SessionFactory自动连线对象写入select 我想使用Hibernate执行select*from employee where username='hesh' @Repository public class EmployeeDaoImpl implements EmployeeDAO{ @Autowir

我正在使用SpringMVC和Hibernate。我使用Hibernate编写insert,但找不到从数据库中写入搜索数据的方法。我在下面的例子中插入了一个我喜欢的过程。如何使用SessionFactory自动连线对象写入select

我想使用Hibernate执行
select*from employee where username='hesh'

@Repository
public class EmployeeDaoImpl implements EmployeeDAO{

@Autowired
private SessionFactory sessionFactory;

@Override
public void AddEmployee(Employee employee) throws ClassNotFoundException, SQLException {
    this.sessionFactory.getCurrentSession().save(employee);  

}}

尝试使用以下方法:

@Override
public List listEmployee(String username) throws Exception{
    Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(Employee.class)
      .add(Restrictions.eq("username", username));  
 criteria.setMaxResults(10);//optionally set max return rows.       
 return criteria.list();
}}