You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Kalle Korhonen <ka...@gmail.com> on 2009/08/27 08:06:44 UTC

Expansions, projections and arrays

I'm using tapestry-hibernate and I have a case where I'm forced to use
Projections (or aggregate functions in hql but same end result) so my
query is returning an object array. Now, I'm rendering a list of that
information to the user, but since using ${obj[0]} expansion is not
supported, I'm forced to write a getter for each synthetic property
(so I can refer to them with ${objProp1}, ${objProp2} etc.) I'm
displaying in my grid. It's not too bad, but is there a better way to
do this? (could do it with ognl, but I would like to avoid adding a
new dependency just for this).

Kalle

PS. Bonus points if you tell me how to make Hibernate return objects
with Criteria api if I only need projections for ordering the result
set.

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


Re: Expansions, projections and arrays

Posted by Sebastian Hennebrueder <us...@laliluna.de>.
Kalle Korhonen schrieb:
> Sebastian, I appreciate the try. But I needed an avg of a field and
> considering that I don't know how to write it in plain sql either
> without the avg being used in the result, I think it cannot be done
> with Criteria either.
> 
> Kalle
> 
In that case, there is no other way.
> 
> On Thu, Aug 27, 2009 at 1:38 AM, Sebastian
> Hennebrueder<us...@laliluna.de> wrote:
>> I am just hitting for the bonus.
>>
>> You don't need projections for ordering just order on a field. if the
>> ordering takes place in a relation, then create an alias and use it in the
>> order condition.
>>
>>
>> Best Regards / Viele Grüße
>>
>> Sebastian Hennebrueder
>> -----
>> Software Developer and Trainer for Hibernate / Java Persistence
>> http://www.laliluna.de
>>
>>
>>
>> Kalle Korhonen schrieb:
>>> I'm using tapestry-hibernate and I have a case where I'm forced to use
>>> Projections (or aggregate functions in hql but same end result) so my
>>> query is returning an object array. Now, I'm rendering a list of that
>>> information to the user, but since using ${obj[0]} expansion is not
>>> supported, I'm forced to write a getter for each synthetic property
>>> (so I can refer to them with ${objProp1}, ${objProp2} etc.) I'm
>>> displaying in my grid. It's not too bad, but is there a better way to
>>> do this? (could do it with ognl, but I would like to avoid adding a
>>> new dependency just for this).
>>>
>>> Kalle
>>>
>>> PS. Bonus points if you tell me how to make Hibernate return objects
>>> with Criteria api if I only need projections for ordering the result
>>> set.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 



-- 
Best Regards / Viele Grüße

Sebastian Hennebrueder
-----
Software Developer and Trainer for Hibernate / Java Persistence
http://www.laliluna.de



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


Re: Expansions, projections and arrays

Posted by Kalle Korhonen <ka...@gmail.com>.
Sebastian, I appreciate the try. But I needed an avg of a field and
considering that I don't know how to write it in plain sql either
without the avg being used in the result, I think it cannot be done
with Criteria either.

Kalle


On Thu, Aug 27, 2009 at 1:38 AM, Sebastian
Hennebrueder<us...@laliluna.de> wrote:
> I am just hitting for the bonus.
>
> You don't need projections for ordering just order on a field. if the
> ordering takes place in a relation, then create an alias and use it in the
> order condition.
>
>
> Best Regards / Viele Grüße
>
> Sebastian Hennebrueder
> -----
> Software Developer and Trainer for Hibernate / Java Persistence
> http://www.laliluna.de
>
>
>
> Kalle Korhonen schrieb:
>>
>> I'm using tapestry-hibernate and I have a case where I'm forced to use
>> Projections (or aggregate functions in hql but same end result) so my
>> query is returning an object array. Now, I'm rendering a list of that
>> information to the user, but since using ${obj[0]} expansion is not
>> supported, I'm forced to write a getter for each synthetic property
>> (so I can refer to them with ${objProp1}, ${objProp2} etc.) I'm
>> displaying in my grid. It's not too bad, but is there a better way to
>> do this? (could do it with ognl, but I would like to avoid adding a
>> new dependency just for this).
>>
>> Kalle
>>
>> PS. Bonus points if you tell me how to make Hibernate return objects
>> with Criteria api if I only need projections for ordering the result
>> set.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: Expansions, projections and arrays

Posted by Sebastian Hennebrueder <us...@laliluna.de>.
I am just hitting for the bonus.

You don't need projections for ordering just order on a field. if the 
ordering takes place in a relation, then create an alias and use it in 
the order condition.


Best Regards / Viele Grüße

Sebastian Hennebrueder
-----
Software Developer and Trainer for Hibernate / Java Persistence
http://www.laliluna.de



Kalle Korhonen schrieb:
> I'm using tapestry-hibernate and I have a case where I'm forced to use
> Projections (or aggregate functions in hql but same end result) so my
> query is returning an object array. Now, I'm rendering a list of that
> information to the user, but since using ${obj[0]} expansion is not
> supported, I'm forced to write a getter for each synthetic property
> (so I can refer to them with ${objProp1}, ${objProp2} etc.) I'm
> displaying in my grid. It's not too bad, but is there a better way to
> do this? (could do it with ognl, but I would like to avoid adding a
> new dependency just for this).
> 
> Kalle
> 
> PS. Bonus points if you tell me how to make Hibernate return objects
> with Criteria api if I only need projections for ordering the result
> set.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 



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


Re: Expansions, projections and arrays

Posted by Kalle Korhonen <ka...@gmail.com>.
Almost brilliant! Except that if I have to write my own transformer or
the bean from scratch, it's still more lines of code than just writing
the getters for the template. There's no way to suppress the
properties you've aliased (right?) but maybe I'll just use
aliasToBean() and create a "DisplayableBean" that inherits from
original - that way I only need to write get/set for the property I'm
using in the orderBy and keep the template as is.

Kalle


On Wed, Aug 26, 2009 at 11:18 PM, Igor
Drobiazko<ig...@gmail.com> wrote:
> You can set a ResultTransformer to your criteria.
>
> https://www.hibernate.org/hib_docs/v3/api/org/hibernate/transform/ResultTransformer.html
>
> On Thu, Aug 27, 2009 at 8:06 AM, Kalle Korhonen
> <ka...@gmail.com>wrote:
>
>> I'm using tapestry-hibernate and I have a case where I'm forced to use
>> Projections (or aggregate functions in hql but same end result) so my
>> query is returning an object array. Now, I'm rendering a list of that
>> information to the user, but since using ${obj[0]} expansion is not
>> supported, I'm forced to write a getter for each synthetic property
>> (so I can refer to them with ${objProp1}, ${objProp2} etc.) I'm
>> displaying in my grid. It's not too bad, but is there a better way to
>> do this? (could do it with ognl, but I would like to avoid adding a
>> new dependency just for this).
>>
>> Kalle
>>
>> PS. Bonus points if you tell me how to make Hibernate return objects
>> with Criteria api if I only need projections for ordering the result
>> set.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> Best regards,
>
> Igor Drobiazko
>

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


Re: Expansions, projections and arrays

Posted by Igor Drobiazko <ig...@gmail.com>.
You can set a ResultTransformer to your criteria.

https://www.hibernate.org/hib_docs/v3/api/org/hibernate/transform/ResultTransformer.html

On Thu, Aug 27, 2009 at 8:06 AM, Kalle Korhonen
<ka...@gmail.com>wrote:

> I'm using tapestry-hibernate and I have a case where I'm forced to use
> Projections (or aggregate functions in hql but same end result) so my
> query is returning an object array. Now, I'm rendering a list of that
> information to the user, but since using ${obj[0]} expansion is not
> supported, I'm forced to write a getter for each synthetic property
> (so I can refer to them with ${objProp1}, ${objProp2} etc.) I'm
> displaying in my grid. It's not too bad, but is there a better way to
> do this? (could do it with ognl, but I would like to avoid adding a
> new dependency just for this).
>
> Kalle
>
> PS. Bonus points if you tell me how to make Hibernate return objects
> with Criteria api if I only need projections for ordering the result
> set.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko