You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Dan Adams <da...@ifactory.com> on 2006/01/20 17:37:52 UTC

sorting table columns in hibernate

Okay, so a have a @Table that list a bunch of objects. Just for
discussion lets say it lists a bunch of City objects where each City may
contain a State object. Now in the table lets say we want to have 2
columns; city name and state name. When you set the columns, you could
do this pretty easily for the city by doing "name:City Name:name" for
example and you could click the column header to sort by the city name.

But what if you want to allow sorting by the state name? If you do
something like "state.name:State name:state.name" I will get a
QueryException from hibernate saying "could not resolve property:
state.name". Is there a way to do this? Right now I have to make columns
like this unsortable but it would be nice if they were sortable.

-- 
Dan Adams
Software Engineer
Interactive Factory


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: sorting table columns in hibernate

Posted by Jesse Kuhnert <jk...@gmail.com>.
My co-worker has a little hibernate table component that handles all of
these things. Ughhh...I can dump that into the new hivemind project as well.
I can send you a link offline if you like (i haven't dumped the table
component in, but can do later today)



On 1/20/06, Patrick Casey <pa...@adelphia.net> wrote:
>
>
>         I don't use the criteria API (highly unnatural results if you
> return
> a joined resultset), so I haven't tried the code exactly as you're doing
> it.
> I just have code that spits out HQL e.g.
>
>         select result from foo.bar.City result where result.state = :state
> order by city.state.name.
>
>         I do seem to recall that there's a different query syntax you're
> going to need if you state is an embedded object as opposed to a joined
> first class object, so it's possible you're running into that as well. If
> we're talking about a joined object you're going ot need something like:
>
>         select result
>                 from City result
>                 join result.state state
>                         where state.population > :population
>                 order by
>                         state.name
>
>         --- Pat
>
> > -----Original Message-----
> > From: Dan Adams [mailto:dan@ifactory.com]
> > Sent: Friday, January 20, 2006 9:09 AM
> > To: Tapestry users
> > Subject: RE: sorting table columns in hibernate
> >
> > If the table name is City what would it be? Because if I try setting the
> > value to City.state.name then I would get back "could not resolve
> > property: City of com.domain.City". The way it is selecting it is
> > basically by using
> >
> > session.createCriteria(City.class).addOrder(Order.asc("City.state.name
> ")).
> > list();
> >
> > On Fri, 2006-01-20 at 08:42 -0800, Patrick Casey wrote:
> > >     city.state.name
> > >
> > >     Or, to use an actual example from an app of mine:
> > >
> > >     person.address.state
> > >
> > >     --- Pat
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

RE: sorting table columns in hibernate

Posted by Patrick Casey <pa...@adelphia.net>.
	I don't use the criteria API (highly unnatural results if you return
a joined resultset), so I haven't tried the code exactly as you're doing it.
I just have code that spits out HQL e.g.

	select result from foo.bar.City result where result.state = :state
order by city.state.name.

	I do seem to recall that there's a different query syntax you're
going to need if you state is an embedded object as opposed to a joined
first class object, so it's possible you're running into that as well. If
we're talking about a joined object you're going ot need something like:

	select result
		from City result 
		join result.state state
			where state.population > :population
		order by
			state.name

	--- Pat

> -----Original Message-----
> From: Dan Adams [mailto:dan@ifactory.com]
> Sent: Friday, January 20, 2006 9:09 AM
> To: Tapestry users
> Subject: RE: sorting table columns in hibernate
> 
> If the table name is City what would it be? Because if I try setting the
> value to City.state.name then I would get back "could not resolve
> property: City of com.domain.City". The way it is selecting it is
> basically by using
> 
> session.createCriteria(City.class).addOrder(Order.asc("City.state.name")).
> list();
> 
> On Fri, 2006-01-20 at 08:42 -0800, Patrick Casey wrote:
> > 	city.state.name
> >
> > 	Or, to use an actual example from an app of mine:
> >
> > 	person.address.state
> >
> > 	--- Pat
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: sorting table columns in hibernate

Posted by Dan Adams <da...@ifactory.com>.
If the table name is City what would it be? Because if I try setting the
value to City.state.name then I would get back "could not resolve
property: City of com.domain.City". The way it is selecting it is
basically by using
 
session.createCriteria(City.class).addOrder(Order.asc("City.state.name")).list();

On Fri, 2006-01-20 at 08:42 -0800, Patrick Casey wrote:
> 	city.state.name
> 
> 	Or, to use an actual example from an app of mine:
> 
> 	person.address.state
> 
> 	--- Pat



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: sorting table columns in hibernate

Posted by Patrick Casey <pa...@adelphia.net>.
	city.state.name

	Or, to use an actual example from an app of mine:

	person.address.state

	--- Pat




> -----Original Message-----
> From: Dan Adams [mailto:dan@ifactory.com]
> Sent: Friday, January 20, 2006 8:38 AM
> To: Tapestry users
> Subject: sorting table columns in hibernate
> 
> Okay, so a have a @Table that list a bunch of objects. Just for
> discussion lets say it lists a bunch of City objects where each City may
> contain a State object. Now in the table lets say we want to have 2
> columns; city name and state name. When you set the columns, you could
> do this pretty easily for the city by doing "name:City Name:name" for
> example and you could click the column header to sort by the city name.
> 
> But what if you want to allow sorting by the state name? If you do
> something like "state.name:State name:state.name" I will get a
> QueryException from hibernate saying "could not resolve property:
> state.name". Is there a way to do this? Right now I have to make columns
> like this unsortable but it would be nice if they were sortable.
> 
> --
> Dan Adams
> Software Engineer
> Interactive Factory
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org