我的問題是,我有一個類,如:是否有休眠的標準涵蓋任何標準包含名單的條件
@Entity
public class Product{
@Id
String id;
String name;
@ManyToMany
List<Tag> tags;
}
@Entity
public class Tag{
@Id
String id;
String name;
}
我要搜索產品的標準像,但reversive爲:
session.createCriteria(Product.class).add(
Restrictions.and(
Restrictions.like("name",name+"%"),
Restrictions.contains("tags",tag)).list();
但顯然Restrictions.contains不存在。我只能通過HQL查詢找到解決方案,但我不想(實際上不能)編寫HQL查詢。
有什麼辦法來處理這與標準?
別名按預期工作,除了當我使用你的代碼時出錯,但是當我編寫爲.add(Restrictions.eq(「tag.id」,tag.getId())時,它工作正常 – bdogru