Kin,
Kintar wrote:
Hi, amulroy. If I understand your question, wouldn't it simply be easier to sort the GridView's model, rather than attempting to bring your results back from the database in a sorted order?
If you must do the sort in the query, for some reason, Hibernate should be smart enough to let you drop in any ORDER BY clause you need. For example:
Code:
FROM Inquiry as i
ORDER BY i.user.name
I'm not 100% sure on that, but since it works with Criteria queries, I don't see why it wouldn't work with HQL.
From the reference manual:
Code:
List results = session.createCriteria(Domestic.class, "cat")
.createAlias("kittens", "kit")
.setProjection( Projections.projectionList()
.add( Projections.property("cat.name"), "catName" )
.add( Projections.property("kit.name"), "kitName" )
)
.addOrder( Order.asc("catName") )
.addOrder( Order.asc("kitName") )
.list();
I hope that helps!
-- Kin
When I try this code from the manual, I keep getting errors - the referenced
property is unknown. My schema is very similar to that of amulroy, with
the names of classes are NetObj and NE where NetObj has a reference
to an instance of NE which has a property, name, which I wish to order by.
Basically I'm doing the equivalent of:
Code:
List results = session.createCriteria(NetObj.class)
.setProjection( Projections.projectionList()
.add( Projections.property("ne.name"))
)
.addOrder( Order.asc("ne.name") )
.list();
or
List results = session.createCriteria(NetObj.class)
.setProjection( Projections.projectionList()
.add( Projections.property("ne"))
)
.addOrder( Order.asc("ne.name") )
.list();
or
List results = session.createCriteria(NetObj.class)
.addOrder( Order.asc("ne.name") )
.list();
I get the same exception in both cases. Tracing into the Hibernate code,
it seems that H is not attempting to follow a path through the "ne" reference. Also, this happens whether or not I use the aliased version
for the specified entities (NetObj and NE).
Any help here would be greatly appreciated.