You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Richard Yunhua Sang <yu...@gmail.com> on 2011/07/11 23:06:17 UTC

tapestry-jpa: JpaGridDataSource sort by a transient field

Hi there,

I am using a Grid with JpaGridDataSource; when I click sort icon on a
transient field of an entity, I get following exception:

Caused by: java.lang.IllegalArgumentException: Unable to resolve attribute
[name] against path
 at
org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:118)
 at
org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:223)
 at
org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:194)
 at
org.apache.tapestry5.jpa.JpaGridDataSource.prepare(JpaGridDataSource.java:98)
 at
org.apache.tapestry5.corelib.components.Grid$CachingDataSource.prepare(Grid.java:311)
 at
org.apache.tapestry5.corelib.components.Grid.setupDataSource(Grid.java:481)
 at org.apache.tapestry5.corelib.components.Grid.setupRender(Grid.java:445)
 at
org.apache.tapestry5.corelib.components.Grid$Shim_415c794d27985.invoke(Unknown
Source)
 at
org.apache.tapestry5.internal.plastic.MethodHandleImpl.invoke(MethodHandleImpl.java:48)
 at
org.apache.tapestry5.internal.transform.BridgeClassTransformation$WrapMethodHandleAsMethodAccess.invoke(BridgeClassTransformation.java:85)
 at
org.apache.tapestry5.internal.transform.RenderPhaseMethodWorker$Invoker.invoke(RenderPhaseMethodWorker.java:117)
 at
org.apache.tapestry5.internal.transform.RenderPhaseMethodWorker$RenderPhaseMethodAdvice.advise(RenderPhaseMethodWorker.java:86)
 at
org.apache.tapestry5.internal.transform.BridgeClassTransformation$WrapMethodAdviceAsComponentMethodAdvice.advise(BridgeClassTransformation.java:349)
 at
org.apache.tapestry5.internal.plastic.AbstractMethodInvocation.proceed(AbstractMethodInvocation.java:86)
 at org.apache.tapestry5.corelib.components.Grid.setupRender(Grid.java)
 at
org.apache.tapestry5.internal.structure.ComponentPageElementImpl$SetupRenderPhase.invokeComponent(ComponentPageElementImpl.java:230)
 at
org.apache.tapestry5.internal.structure.ComponentPageElementImpl$AbstractPhase.invoke(ComponentPageElementImpl.java:191)
Also can JpaGridDataSource provide the way to sort the result at local
instead of database?

Overall it's pleasant to work with JPA module, thanks a lot for the great
job!

Yunhua

Re: tapestry-jpa: JpaGridDataSource sort by a transient field

Posted by Richard Yunhua Sang <yu...@gmail.com>.
HI Igor,

I have a small Maven project to demonstrate this problem, can I send it as a
zip file to your personal gmail address?

Thanks,
Yunhua


On Mon, Jul 11, 2011 at 5:19 PM, Igor Drobiazko <ig...@gmail.com>wrote:

> Can you please provide more details? Perfectly some source code to
> reproduce
> the issue.
>
> On Mon, Jul 11, 2011 at 11:06 PM, Richard Yunhua Sang <
> yunhua.sang@gmail.com
> > wrote:
>
> > Hi there,
> >
> > I am using a Grid with JpaGridDataSource; when I click sort icon on a
> > transient field of an entity, I get following exception:
> >
> > Caused by: java.lang.IllegalArgumentException: Unable to resolve
> attribute
> > [name] against path
> >  at
> >
> >
> org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:118)
> >  at
> >
> >
> org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:223)
> >  at
> >
> >
> org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:194)
> >  at
> >
> >
> org.apache.tapestry5.jpa.JpaGridDataSource.prepare(JpaGridDataSource.java:98)
> >  at
> >
> >
> org.apache.tapestry5.corelib.components.Grid$CachingDataSource.prepare(Grid.java:311)
> >  at
> >
> org.apache.tapestry5.corelib.components.Grid.setupDataSource(Grid.java:481)
> >  at
> org.apache.tapestry5.corelib.components.Grid.setupRender(Grid.java:445)
> >  at
> >
> >
> org.apache.tapestry5.corelib.components.Grid$Shim_415c794d27985.invoke(Unknown
> > Source)
> >  at
> >
> >
> org.apache.tapestry5.internal.plastic.MethodHandleImpl.invoke(MethodHandleImpl.java:48)
> >  at
> >
> >
> org.apache.tapestry5.internal.transform.BridgeClassTransformation$WrapMethodHandleAsMethodAccess.invoke(BridgeClassTransformation.java:85)
> >  at
> >
> >
> org.apache.tapestry5.internal.transform.RenderPhaseMethodWorker$Invoker.invoke(RenderPhaseMethodWorker.java:117)
> >  at
> >
> >
> org.apache.tapestry5.internal.transform.RenderPhaseMethodWorker$RenderPhaseMethodAdvice.advise(RenderPhaseMethodWorker.java:86)
> >  at
> >
> >
> org.apache.tapestry5.internal.transform.BridgeClassTransformation$WrapMethodAdviceAsComponentMethodAdvice.advise(BridgeClassTransformation.java:349)
> >  at
> >
> >
> org.apache.tapestry5.internal.plastic.AbstractMethodInvocation.proceed(AbstractMethodInvocation.java:86)
> >  at org.apache.tapestry5.corelib.components.Grid.setupRender(Grid.java)
> >  at
> >
> >
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl$SetupRenderPhase.invokeComponent(ComponentPageElementImpl.java:230)
> >  at
> >
> >
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl$AbstractPhase.invoke(ComponentPageElementImpl.java:191)
> > Also can JpaGridDataSource provide the way to sort the result at local
> > instead of database?
> >
> > Overall it's pleasant to work with JPA module, thanks a lot for the great
> > job!
> >
> > Yunhua
> >
>
>
>
> --
> Best regards,
>
> Igor Drobiazko
> http://tapestry5.de
>

Re: tapestry-jpa: JpaGridDataSource sort by a transient field

Posted by Igor Drobiazko <ig...@gmail.com>.
Can you please provide more details? Perfectly some source code to reproduce
the issue.

On Mon, Jul 11, 2011 at 11:06 PM, Richard Yunhua Sang <yunhua.sang@gmail.com
> wrote:

> Hi there,
>
> I am using a Grid with JpaGridDataSource; when I click sort icon on a
> transient field of an entity, I get following exception:
>
> Caused by: java.lang.IllegalArgumentException: Unable to resolve attribute
> [name] against path
>  at
>
> org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:118)
>  at
>
> org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:223)
>  at
>
> org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:194)
>  at
>
> org.apache.tapestry5.jpa.JpaGridDataSource.prepare(JpaGridDataSource.java:98)
>  at
>
> org.apache.tapestry5.corelib.components.Grid$CachingDataSource.prepare(Grid.java:311)
>  at
> org.apache.tapestry5.corelib.components.Grid.setupDataSource(Grid.java:481)
>  at org.apache.tapestry5.corelib.components.Grid.setupRender(Grid.java:445)
>  at
>
> org.apache.tapestry5.corelib.components.Grid$Shim_415c794d27985.invoke(Unknown
> Source)
>  at
>
> org.apache.tapestry5.internal.plastic.MethodHandleImpl.invoke(MethodHandleImpl.java:48)
>  at
>
> org.apache.tapestry5.internal.transform.BridgeClassTransformation$WrapMethodHandleAsMethodAccess.invoke(BridgeClassTransformation.java:85)
>  at
>
> org.apache.tapestry5.internal.transform.RenderPhaseMethodWorker$Invoker.invoke(RenderPhaseMethodWorker.java:117)
>  at
>
> org.apache.tapestry5.internal.transform.RenderPhaseMethodWorker$RenderPhaseMethodAdvice.advise(RenderPhaseMethodWorker.java:86)
>  at
>
> org.apache.tapestry5.internal.transform.BridgeClassTransformation$WrapMethodAdviceAsComponentMethodAdvice.advise(BridgeClassTransformation.java:349)
>  at
>
> org.apache.tapestry5.internal.plastic.AbstractMethodInvocation.proceed(AbstractMethodInvocation.java:86)
>  at org.apache.tapestry5.corelib.components.Grid.setupRender(Grid.java)
>  at
>
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl$SetupRenderPhase.invokeComponent(ComponentPageElementImpl.java:230)
>  at
>
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl$AbstractPhase.invoke(ComponentPageElementImpl.java:191)
> Also can JpaGridDataSource provide the way to sort the result at local
> instead of database?
>
> Overall it's pleasant to work with JPA module, thanks a lot for the great
> job!
>
> Yunhua
>



-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: tapestry-jpa: JpaGridDataSource sort by a transient field

Posted by Taha Hafeez <ta...@gmail.com>.
Imagine the implementation

if(there_is_a_transient_field)
{
   populate_all_data();
   sort_yourself_based_on_sort_constraint();
   paginate();
}
else
{
   pass_the_paging_and_sort_constraints_to_jpa();
}

Instead you already have a JPAGridDataSource and you can have your own
JPAInMemoryGridDataSource implementation :)

regards
Taha


On Tue, Jul 12, 2011 at 5:28 AM, Richard Yunhua Sang
<yu...@gmail.com>wrote:

> Hi Taha,
>
> I have no problem to write a new GridDataSource to do such thing; but as I
> said, it would be good to have this function in JPAGridDataSource.
>
> e.g.
>
> @Entity
> public class Student {
>
>    @Id
>    @GeneratedValue(strategy = GenerationType.IDENTITY)
>    private Long id;
>
>    private String firstName;
>
>    private String lastName;
>
>    public Long getId() {
>        return id;
>    }
>
>    public void setId(Long id) {
>        this.id = id;
>    }
>
>    public String getFirstName() {
>        return firstName;
>    }
>
>    public void setFirstName(String firstName) {
>        this.firstName = firstName;
>    }
>
>    public String getLastName() {
>        return lastName;
>    }
>
>    public void setLastName(String lastName) {
>        this.lastName = lastName;
>    }
>
>    @Transient
>    public String getName() {
>        return firstName + " " + lastName;
>    }
>
> }
>
> The users may want to show name only, and want to sort the list by name
> naturally.
>
> Thanks,
> Yunhua
>
>
>
> On Mon, Jul 11, 2011 at 7:43 PM, Taha Hafeez <tawus.tapestry@gmail.com
> >wrote:
>
> > Hi Richard,
> >
> > Internally JPAGridDataSource does not handle sorting itself, instead it
> > delegates it to JPA and transient values are unknown to JPA. If you want
> to
> > handle transient values, you will have to write you own implementation of
> > GridDataSource where in you can retrieve all the rows from the database
> and
> > based on the SortConstraints passed to prepare() method, sort the values
> > yourself.
> >
> > regards
> > Taha
> >
> > On Tue, Jul 12, 2011 at 4:58 AM, Richard Yunhua Sang
> > <yu...@gmail.com>wrote:
> >
> > > Thanks for your reply, but I do want to sort the result by transient
> > field
> > > in Grid. It would be appreciated that the JPAGridDataSource is able to
> > sort
> > > the result within JVM.
> > >
> > > On Mon, Jul 11, 2011 at 5:29 PM, Thiago H. de Paula Figueiredo <
> > > thiagohp@gmail.com> wrote:
> > >
> > > > On Mon, 11 Jul 2011 18:06:17 -0300, Richard Yunhua Sang <
> > > > yunhua.sang@gmail.com> wrote:
> > > >
> > > >  Hi there,
> > > >>
> > > >
> > > > Hi!
> > > >
> > > >
> > > >  I am using a Grid with JpaGridDataSource; when I click sort icon on
> a
> > > >> transient field of an entity, I get following exception:
> > > >>
> > > >
> > > > I don't think any GridDataSource implementation backed by a database
> > > would
> > > > be able to handle transient properties, so you should set their
> > > > corresponding PropertyModel's as unsortable. To get the
> PropertyModel,
> > > > create a BeanModel for you entity class using the BeanModelSource
> > service
> > > > and use its get() method.
> > > >
> > > > --
> > > > Thiago H. de Paula Figueiredo
> > > > Independent Java, Apache Tapestry 5 and Hibernate consultant,
> > developer,
> > > > and instructor
> > > > Owner, Ars Machina Tecnologia da Informação Ltda.
> > > > http://www.arsmachina.com.br
> > > >
> > >
> >
>

Re: tapestry-jpa: JpaGridDataSource sort by a transient field

Posted by Richard Yunhua Sang <yu...@gmail.com>.
Hi Taha,

I have no problem to write a new GridDataSource to do such thing; but as I
said, it would be good to have this function in JPAGridDataSource.

e.g.

@Entity
public class Student {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String firstName;

    private String lastName;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Transient
    public String getName() {
        return firstName + " " + lastName;
    }

}

The users may want to show name only, and want to sort the list by name
naturally.

Thanks,
Yunhua



On Mon, Jul 11, 2011 at 7:43 PM, Taha Hafeez <ta...@gmail.com>wrote:

> Hi Richard,
>
> Internally JPAGridDataSource does not handle sorting itself, instead it
> delegates it to JPA and transient values are unknown to JPA. If you want to
> handle transient values, you will have to write you own implementation of
> GridDataSource where in you can retrieve all the rows from the database and
> based on the SortConstraints passed to prepare() method, sort the values
> yourself.
>
> regards
> Taha
>
> On Tue, Jul 12, 2011 at 4:58 AM, Richard Yunhua Sang
> <yu...@gmail.com>wrote:
>
> > Thanks for your reply, but I do want to sort the result by transient
> field
> > in Grid. It would be appreciated that the JPAGridDataSource is able to
> sort
> > the result within JVM.
> >
> > On Mon, Jul 11, 2011 at 5:29 PM, Thiago H. de Paula Figueiredo <
> > thiagohp@gmail.com> wrote:
> >
> > > On Mon, 11 Jul 2011 18:06:17 -0300, Richard Yunhua Sang <
> > > yunhua.sang@gmail.com> wrote:
> > >
> > >  Hi there,
> > >>
> > >
> > > Hi!
> > >
> > >
> > >  I am using a Grid with JpaGridDataSource; when I click sort icon on a
> > >> transient field of an entity, I get following exception:
> > >>
> > >
> > > I don't think any GridDataSource implementation backed by a database
> > would
> > > be able to handle transient properties, so you should set their
> > > corresponding PropertyModel's as unsortable. To get the PropertyModel,
> > > create a BeanModel for you entity class using the BeanModelSource
> service
> > > and use its get() method.
> > >
> > > --
> > > Thiago H. de Paula Figueiredo
> > > Independent Java, Apache Tapestry 5 and Hibernate consultant,
> developer,
> > > and instructor
> > > Owner, Ars Machina Tecnologia da Informação Ltda.
> > > http://www.arsmachina.com.br
> > >
> >
>

Re: tapestry-jpa: JpaGridDataSource sort by a transient field

Posted by Taha Hafeez <ta...@gmail.com>.
Hi Richard,

Internally JPAGridDataSource does not handle sorting itself, instead it
delegates it to JPA and transient values are unknown to JPA. If you want to
handle transient values, you will have to write you own implementation of
GridDataSource where in you can retrieve all the rows from the database and
based on the SortConstraints passed to prepare() method, sort the values
yourself.

regards
Taha

On Tue, Jul 12, 2011 at 4:58 AM, Richard Yunhua Sang
<yu...@gmail.com>wrote:

> Thanks for your reply, but I do want to sort the result by transient field
> in Grid. It would be appreciated that the JPAGridDataSource is able to sort
> the result within JVM.
>
> On Mon, Jul 11, 2011 at 5:29 PM, Thiago H. de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
> > On Mon, 11 Jul 2011 18:06:17 -0300, Richard Yunhua Sang <
> > yunhua.sang@gmail.com> wrote:
> >
> >  Hi there,
> >>
> >
> > Hi!
> >
> >
> >  I am using a Grid with JpaGridDataSource; when I click sort icon on a
> >> transient field of an entity, I get following exception:
> >>
> >
> > I don't think any GridDataSource implementation backed by a database
> would
> > be able to handle transient properties, so you should set their
> > corresponding PropertyModel's as unsortable. To get the PropertyModel,
> > create a BeanModel for you entity class using the BeanModelSource service
> > and use its get() method.
> >
> > --
> > Thiago H. de Paula Figueiredo
> > Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> > and instructor
> > Owner, Ars Machina Tecnologia da Informação Ltda.
> > http://www.arsmachina.com.br
> >
>

Re: tapestry-jpa: JpaGridDataSource sort by a transient field

Posted by Tony Nelson <tn...@starpoint.com>.
We solved a similar problem by creating a view that calculated the field instead of using a transient field.

Then we just mapped the view as a read only object and all the sorting worked.

-Tony

On Jul 11, 2011, at 7:28 PM, Richard Yunhua Sang wrote:

> Thanks for your reply, but I do want to sort the result by transient field
> in Grid. It would be appreciated that the JPAGridDataSource is able to sort
> the result within JVM.
> 
> On Mon, Jul 11, 2011 at 5:29 PM, Thiago H. de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
> 
>> On Mon, 11 Jul 2011 18:06:17 -0300, Richard Yunhua Sang <
>> yunhua.sang@gmail.com> wrote:
>> 
>> Hi there,
>>> 
>> 
>> Hi!
>> 
>> 
>> I am using a Grid with JpaGridDataSource; when I click sort icon on a
>>> transient field of an entity, I get following exception:
>>> 
>> 
>> I don't think any GridDataSource implementation backed by a database would
>> be able to handle transient properties, so you should set their
>> corresponding PropertyModel's as unsortable. To get the PropertyModel,
>> create a BeanModel for you entity class using the BeanModelSource service
>> and use its get() method.
>> 
>> --
>> Thiago H. de Paula Figueiredo
>> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
>> and instructor
>> Owner, Ars Machina Tecnologia da Informação Ltda.
>> http://www.arsmachina.com.br
>> 


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


Re: tapestry-jpa: JpaGridDataSource sort by a transient field

Posted by Richard Yunhua Sang <yu...@gmail.com>.
Thanks for your reply, but I do want to sort the result by transient field
in Grid. It would be appreciated that the JPAGridDataSource is able to sort
the result within JVM.

On Mon, Jul 11, 2011 at 5:29 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Mon, 11 Jul 2011 18:06:17 -0300, Richard Yunhua Sang <
> yunhua.sang@gmail.com> wrote:
>
>  Hi there,
>>
>
> Hi!
>
>
>  I am using a Grid with JpaGridDataSource; when I click sort icon on a
>> transient field of an entity, I get following exception:
>>
>
> I don't think any GridDataSource implementation backed by a database would
> be able to handle transient properties, so you should set their
> corresponding PropertyModel's as unsortable. To get the PropertyModel,
> create a BeanModel for you entity class using the BeanModelSource service
> and use its get() method.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>

Re: tapestry-jpa: JpaGridDataSource sort by a transient field

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 11 Jul 2011 18:06:17 -0300, Richard Yunhua Sang  
<yu...@gmail.com> wrote:

> Hi there,

Hi!

> I am using a Grid with JpaGridDataSource; when I click sort icon on a
> transient field of an entity, I get following exception:

I don't think any GridDataSource implementation backed by a database would  
be able to handle transient properties, so you should set their  
corresponding PropertyModel's as unsortable. To get the PropertyModel,  
create a BeanModel for you entity class using the BeanModelSource service  
and use its get() method.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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