On 21/05/2012 21:27, Carlucci, Tony wrote:
-----Original Message-----
From: Paul Sharples [mailto:[email protected]]
Sent: Monday, May 21, 2012 7:37 AM
To: [email protected]
Subject: Re: [DISCUSS] Shared Spaces bug with sub-page ordering

On 17/05/2012 21:43, Carlucci, Tony wrote:
Hello Rave devs, I came across a bug related to the shared spaces code that
I'm not quite sure how to best solve.  It involves the render order of the sub-
pages (for example on the Person Profile page).  On occasion I've noticed that
the sub page tabs were not rendering in their proper order, even though I
verified that the PageUser#renderSequence values were correct in the
database.    The issue is that the Page#subPages list no longer has an OrderBy
annotation, which leaves the ordering of the data up to the database (hence
the occasional inconsistency).
So, in theory, we need to put an OrderBy annotation back on the
Page#subPages list - something along the lines of
@OrderBy("members.renderSequence").   However, there is a limitation in
JPA where you can't order a list based on properties of entities in a sublist 
(in
this case trying to order on renderSequence of List<PageUser>   members).
What do you think the best approach would be to ensure the subPages are
returned in their proper order?  One solution would be to manually sort the
subPages List in the Page#getSubPages() getter method, but that would not
be the most efficient.  Any better ideas?

I've been re-reading the JPA documentation and trying to to figure out
another way of doing this, but unfortunately I haven't been able to come
up with another way using the current page&  pageUser design.  One
alternative I thought about could be that we update references to
ParentPage and subpages in 'Page.class' and make them of type PageUser,
rather than Page.

i.e. in Page.class

     @OneToOne(cascade=CascadeType.ALL)
     @JoinColumn(name="parent_page_id")
     private PageUser parentPageUser;

     @OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL,
mappedBy="parentPageUser")
     @OrderBy("renderSequence")
     private List<PageUser>  subPageUsers;

That way we should be able to get the subpages using the renderSequence
found in the PageUser entity. The effect of this would be that anywhere
else in the code where ParentPage&  subpages are referenced, we would
have to update the calls so they navigate through the pageUser object
first.

For example...

// as is now
PageType parentPageType = page.getParentPage().getPageType()

// updated method
PageType parentPageType =
page.getParentPageUser().getPage().getPageType()

However, I am unsure if this solution would be any better than just
doing a sort in the Page#getSubPages() getter method as you originally
suggested.

Paul
After reviewing your suggestion, as well as the current data model, I've come to 
the conclusion that the way I initially implemented the Page->SubPage 
relationship probably wasn't the best model for supporting Shared Spaces :)  I 
know there will be some significant data model changes with the pages that will 
come along with the JCR work Ate and crew are doing, so for now I've committed a 
manual sort in Page#getSubPages that will ensure the sub-pages get ordered 
properly.  Feel free to look it over and let me know what you think...

I agree this was the way to go for now. The subpages are now sequenced correctly according to the pageUser rendersequence.

(good catch in the first place)

Paul


Tony

Thanks, Tony





Reply via email to