hibernate 模糊查询(ssh框架)
[code=Java][/code]public List findBymohu(String name, String address, int depart,int userinfo) {
Session s = getSession();
Transaction tx = s.beginTransaction();
String Hql = "from Room as r where 1=1 ";
if (name != null) {
Hql += " and r.name like '%" + name + "%'";
}
if (address != null) {
Hql += " and r.address='%" + address + "%'";
}
if (depart != 0) {
Hql += " and r.department.did= " + depart;
}
if (userinfo != 0) {
Hql += " and r.userinfo.uid= " + userinfo;
}
Hql += " order by r.rid desc";
System.out.println(" nnnnnnnnn");
List list = s.createQuery(Hql).list();
System.out.println(" cccccccc");
tx.commit();
s.flush();
s.close();
return list;
}
执行了nnnnnn 没有执行cccccccccc
没有提交去查询
ssh框架 我不需要这里有事务! 因为spring 已经帮我处理了!
------解决方案--------------------事务重复是有问题的
事务与事务之间是相互独立的
不能嵌套的
------解决方案-------------------- if (name != null) {
Hql += " and r.name like '%" + name + "%'";
}
if (address != null) {
Hql += " and r.address like '%" + address + "%'";
}
if (depart != 0) {
Hql += " and r.department.did= " + depart;
}
if (userinfo != 0) {
Hql += " and r.userinfo.uid= " + userinfo;
}
Hql += " order by r.rid desc";
}