我有以下实体(不准确,但给出了一个总体思路):不同结果的读取与查询API的结果与HQL
@Entity public class WebElement implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }) private Set<CoreElement> coreElements; private String agent; // ... omitting const' get/set hashcode equals etc. }
public class CoreElement implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; private String value; // ... omitting const' get/set hashcode equals etc. }
我的问题是试图使用Criteria
API来获取WebElements
时与HQL
当执行以下时,我得到一个空的列表。
getCurrentSession().createCriteria(WebElement.class) .createCriteria("coreElements").add( Restrictions.eq("value", value)).list();
但在执行以下HQL当我得到正确的结果。
select distinct we from WebElement we, in(we.coreElements) core where core.value = :inputValue
你能帮找到我在做什么呼叫之间错误或有什么不同?
(注意我的选择是与标准API工作HQLs代替。
也尝试过,取模不改变结果。我用HQL离开了它,但是这个问题仍然让我感到担忧。 – Bivas 2010-10-19 15:20:21
告诉我们你的代码然后... – 2010-10-19 15:45:09