hql模糊查询与去重

hql语句

String hql = "from Song  where name like '%"+text+"%' or singer like '%"+text+"%' or alumn like '%"+text+"%'  ";

去重。重写pojo类的equals 和hascode。

@Override
public int hashCode() {
// TODO Auto-generated method stub
return 1;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof Song) {
Song song = (Song) obj;
if (this.id.equals(song.getId())) {
return true;
}
}
return false;
}

 

 

我的主键是id。我只需要结果中的id不同就可以。如需其他条件的可以自己修改。

然后把list集合转到Hashset里面去重即可。

posted @ 2016-01-17 21:57  Lemniscate317  阅读(507)  评论(0编辑  收藏  举报