hibernate 使用in方式删除数据

hibernate 3.0,

1、使用sql语句,动态参数

 

SQLQuery query;
List list = Arrays.asList(ids.split(","));
sql = "delete from table where id in (:ids) ";
query = session.createSQLQuery(sql);
query.setParameterList("ids", list);

 

hibernate会根据list数量生成SQL:delete from table where id in (?,?...);

 

2、没有动态参数,在hibernate 2.0中的session.delete会有效率问题,hibernate3.0中用下面方法没效率问题

sql = "delete from table where id >65000 ";
query = session.createSQLQuery(sql);
query.executeUpdate();

 

Query query = session.createQuery("delete from Pojo where id>60000 and id<65000");
query.executeUpdate();
 

 

3、QBC

 

 

你可能感兴趣的:(Hibernate)