[英]how to write query in hibernate
I have one table, User , and in that table, I have 3 columns:我有一个表User ,在该表中,我有 3 列:
I want to retrieve a name for a particular email by passing the email id;我想通过传递 email id 来检索特定 email 的名称; how would I write that hibernate query?我将如何编写 hibernate 查询?
Using a criteria query:使用条件查询:
Criteria criteria = getSession().createCriteria(User.class);
criteria = criteria.add(Restrictions.eq("email", email));
List<User> results = (List<User>) criteria.list();
Using hql:使用 hql:
String hql = "from User where email = :email";
Query query = getSession().createQuery(hql);
query.setParameter("email", email);
List<User> results = (List<User>) query.list();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.