关于hibernatetemplate的问题,求高手回答,救命啊!

yulong11 2012-01-18 03:08:49
我现在建了一个User 一个Email 是一个一对多的关联关系,查询User的时候直接用getEmail方法得到当前登录User的所有Email的Set集合,但是我现在要添加删除邮件的功能,所以加了一个removed字段,removed是false的时候代表没有删除的Email,removed是true的时候是垃圾箱的Email,所以我现在要在查询的Email上加removed的限制条件,怎么加啊!求高手啊!在线等啊!用的是hibernatetemplate
...全文
150 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
gsdhaiji_cai 2012-01-19
  • 打赏
  • 举报
回复
我也只想到用hql来弄比较方便

如果非要用getEmails方式的且不使用数据库查询语句,那就是把所有的取出来。然后一个一个判断。。这样效率也不好

个人感觉。。
jumpheightway 2012-01-19
  • 打赏
  • 举报
回复
你的问题就是换个目录
那你改变你的pojo对象状态不就得了
yulong11 2012-01-18
  • 打赏
  • 举报
回复
email不是直接查询数据库得到的 是一对多关联关系,先得到User 直接用getEmail方法得到的Set集合
yulong11 2012-01-18
  • 打赏
  • 举报
回复
/*
* 得到当前登录的用户
*/
@Override
public User getCurrentUser(int id){
return (User)this.getHibernateTemplate().get(User.class, id);
}
yulong11 2012-01-18
  • 打赏
  • 举报
回复
@Override
public String execute() throws Exception {
int userid = (Integer)ServletActionContext.getRequest().getSession().getAttribute("userid");
this.user = this.service.getCurrentUser(userid);
ServletActionContext.getRequest().setAttribute("emails",this.user.getEmails());
return SUCCESS;
}
我现在能得到登录用户下的所有email,ServletActionContext.getRequest().setAttribute("emails",this.user.getEmails());是发到页面上去,但这是所有email,我想加removed条件
enke_zhang 2012-01-18
  • 打赏
  • 举报
回复
直接在hql语句里面加查询条件就可以啦
xz5211314_0 2012-01-18
  • 打赏
  • 举报
回复
 queryString= "from ConsArea  s where s.xx="+Id+" and s.yy=2";

getHibernateTemplate().find(queryString)

xz5211314_0 2012-01-18
  • 打赏
  • 举报
回复
hibernatetemplate.execute(sql) 查询啊

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧