A表:User表
private Long id;
/**
* 用户名
/
private String name;
/*
* 登陆密码
/
private String password ;
/*
* 创建时间
*/
private String createtime;
B 表:WorkLog表
private Long id;
/**
* 上传用户
*/
private CUser user;
/**
* 工作类型
*/
private String workTypeId;
/**
* 创建时间
*/
private String createtime;
A,B两表关联,
SQL写法:
select t.* from c_worklog t where to_char(to_date(trim(t.createtime),'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd') = '2011-04-12' and t.userid in (select c.id from c_user c where c.name ='2377');可以执行成功
QBC写法:
public List search(Map map, int firstresult, int maxresults) {
// TODO Auto-generated method stub
List list1 = null;
try
{
Criteria criteria = this.getSession().createCriteria(CWorkLog.class);
Iterator it = map.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pairs = (Map.Entry) it.next();
if(pairs.getKey().equals("createtime")){
criteria = criteria.add(
Restrictions
.sqlRestriction(
" to_char(to_date(trim(createtime),'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd') = ?",
pairs.getValue().toString().trim(),
Hibernate.STRING));
}else if (pairs.getKey().equals("name"))
{
criteria = criteria.createCriteria("user").add(Restrictions.eq("name", pairs.getValue()
.toString()));
}
}
list1 =criteria.setFirstResult(
(firstresult - 1) * maxresults).setMaxResults(maxresults).list();
}
catch (Exception e)
{
e.printStackTrace();
}
return list;
}
[color=red]QBC执行时候单个查询例如:进行createtime或者name查询都可以,但是两个合并查询就出错:ORA-00918: 未明确定义列[/color]