hibernate查询语句

本文详细介绍了使用Hibernate进行数据库查询的方法,包括where条件查询、模糊查询、传参数的查询、where条件删除以及级联查询等。通过实例代码演示了如何在实际应用中运用这些查询技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用hibernate做查询,简单列举几个查询小例子

1、where条件查询

String hql = "form tableName table_name where table_name.column = '该列指定的值' ";

List<E> list = this.getHibernateTemplate().find(hql);

2、模糊查询

String hql = "from tableName table_name where table_name.column like '%模糊查询中指定的值%'";

List<E> list = this.getHibernateTemplate().find(hql);

3、传参数的查询

String hql = "from tableName table_name where table_name.column >= :value";

Query query = session.createQuery(hql);  
query.setDate("
value",new Date(date)); //此处可以根据要传的参数的真实类型来自己设定

List<E> list = query.list();

4、where条件删除

String hql = "delete from tableName where column='"+指定的值+"'";
Query query = session.createQuery(hql);  
query.executeUpdate();

5、级联查询

Criteria criteria = session.createCriteria(TableInfo.class);
criteria.createAlias("
column","s_column");
                criteria.add(Restrictions.eq("
s_column.id",指定的值));
L
ist<E> list = criteria.list();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值