cheeser wrote:
I think this is what you are looking for:
Code:
Criteria criteria = session.createCriteria(Invoice.class)
.createCriteria(StatusChange.class)
.add(Restrictions.eq("status", "new"))
.add(Restrictions.eq("isCurrent", true));
Almost correct ;)
Code:
Criteria criteria = session.createCriteria(Invoice.class)
.createCriteria("history")
.add(Restrictions.eq("status", "new"))
.add(Restrictions.eq("current", true));
The base Criteria you specify by Class.. each relation you specify by creating a criteria for that relation by attribute name.
So this works as well:
Code:
Criteria invoiceCriteria = session.createCriteria(Invoice.class);
Criteria historyCriteria = invoiceCriteria.createCriteria("history");
historyCriteria.add(Restrictions.eq("status", "new")).add(Restrictions.eq("current", true));
Criteria otherCriteria = invoiceCriteria.createCriteria("otherAttribute");
otherCriteria.add(Restrictions.gt("value", value);
// etc..
N.B.
You property isCurrent should be called only current.
The methods for this property than will be isCurrent() and setCurrent();
That is the normal standard for boolean attributes.
And I thought that the reflection, used by Hibernate will search for a 'get' or 'is' method to get the attributes value.
So if you specify 'isCurrent' in you Criteria, Hibernate will probably seach for getIsCurrent() or isIsCurrent ;)[/b]