I am using Hibernate 2 beta 3.
I can use the criteria api successfully to query properties of the
'root' persistent class (OrderItem.class)
Criteria = session.createCriteria(OrderItem.class);
though when I want to query acros a many to one relationship, I can't
work out how to do it.
I have an existing text query that I want to convert to allow me to make
options optional :
String txt = "from orderItem in class " + OrderItem.class.getName() ;
String joiner = " where ";
if (filter.getState() != null) {
txt = txt + joiner + " orderItem.order.state = :orderState";
joiner = " and ";
}
... more filter options here ...
Query q = hibernateSession.createQuery(txt);
if (filter.getState() != null) {
q.setParameter("orderState", filter.getState());
}
.. more param bindings here ..
I have tried this :
Criteria criteria = hibernateSession.createCriteria(OrderItem.class);
if (filter.getState() != null) {
criteria.add(Expression.eq("order.state", filter.getState()));
}
Which results in an error saying that 'order' ...
I have tried using aliases - though I don't know what I am doing here ;)
criteria.createAlias("order", "order");
I have tried using "this.order.state" instead of "order.state"
I have run out of ideas.
Can anyone help ?
Thanks.
Cameron
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel