我正在使用以下对象:
RawRead RawRead.Checkpoint
检查点.EndCustomer
警卫
其中 Checkpoint 和 Guard 是 RawRead 的属性,EndCustomer 是 Checkpoint 的属性。都是对象。
我当前的 Hibernate gubbins:
Criteria crit = sess.createCriteria(RawRead.class);
crit.add(
Restrictions.or(
Restrictions.eq("checkpoint", null),
Restrictions.in("checkpoint.parentEndCustomer",collectionOfEndCustomers)
)
);
所以 Checkpoint 可以为空,但如果它在那里,我只想要 parentEndCustomer 对象位于 checkpoint.parentEndCustomer 属性中的 RawRead 对象。
我希望这是有道理的。
我上面的猜测产生了一个错误,(对我来说)表明我的标准被错误地指定:
[Request processing failed; nested exception is org.hibernate.QueryException: could not resolve property: checkpoint.parentEndCustomer of: uk.co.romar.guardian.objects.RawRead] with root cause org.hibernate.QueryException:
could not resolve property: checkpoint.parentEndCustomer of: uk.co.romar.guardian.objects.RawRead at
org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:81) at
org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:96) at
org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:62) at
org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1457) at
org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:483)
RawRead 的相关位:
@ManyToOne
@JoinColumn(name="CHECKPOINT_OID")
@NotFound(action=NotFoundAction.IGNORE)
public Checkpoint checkpoint = null;
public void setCheckpoint(Checkpoint in) {this.checkpoint = in;}
public Checkpoint getCheckpoint() {return this.checkpoint;}
@ManyToOne
@JoinColumn(name="GUARD_OID")
@NotFound(action=NotFoundAction.IGNORE)
private Guard guard = null;
public void setGuard(Guard in) {this.guard = in;}
public Guard getGuard() {return this.guard;}
从检查点:
@ManyToOne
@JoinColumn(name="ENDCUSTOMER_OID")
@NotFound(action=NotFoundAction.IGNORE)
private EndCustomer parentEndCustomer = null;
public EndCustomer getParentEndCustomer() {return this.parentEndCustomer;}
public void setParentEndCustomer(EndCustomer ownerCustomer) {this.parentEndCustomer = ownerCustomer;}
编辑在执行下面的第一个答案之后。
如果我在数据库中有一些这样的数据(我希望这个符号有意义!):
RawRead {
ID=1
checkpoint={id=1,parentEndCustomer={ID=1}}
}
RawRead {
ID=2
checkpoint={id=4,parentEndCustomer={ID=4}}
}
RawRead {
ID=3
checkpoint={id=7,parentEndCustomer={ID=31}}
}
RawRead {
ID=4
checkpoint={null}
}
Restriction 中给出的 collectionOfEndCustomers 是这样的: EndCustomer={ID=31}
我只想检索 RawReads 3 和 4。RawRead 1 和 2 被拒绝,因为子检查点属性的 parentEndCustomer 与传入到 collectionOfEndCustomers 中的限制不匹配。
应该选择 RawRead.3,因为 parentEndCustomer 匹配传入的集合中的一个。应该选择 RawRead.4,因为检查点为空。
遵循以下第一个答案中的指导会导致返回所有上述 RawReads 而不是我所追求的子集。