有两个具有@OneToMany 和@ManyToOne 双向关系的表,如下所示:
@Entity
public class Asset {
private int id;
private int count;
@OneToMany
private Set<Dealing> dealings;
...
}
@Entity
public class Dealing {
private int id;
...
@ManyToOne
@JoinColumn(name = "customer_id", nullable = false, updatable = false)
private Customer customer;
@ManyToOne
@JoinColumn(name = "product_id", nullable = false, updatable = false)
private Product product;
@ManyToOne(cascade = CascadeType.ALL)
private Asset asset;
}
一切听起来都不错,但是当我想像这样使用 Restriction 搜索数据时,
session.createCriteria(Asset.class).add(Restrictions.eq("dealings.customer.id", customerId)).add(Restrictions.eq("dealing.product.id", productId)).list();
在这个级别我得到这个错误,
could not resolve property: dealings.customer of: com.project.foo.model.Asset
解决方案之一是改变我的策略,但我浪费时间找到这个,顺便说一句,我对此一无所知,是吗?