You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Greendog <ma...@gmail.com> on 2011/10/25 14:57:21 UTC

Multizone updating and hibernate session loss

   Hi, everybody. First of all, as a new forum user, I'd like to thank you
all for the great job you're doing here. That said, here we go...

    I'm having trouble with an issue in a tapestry-hibernate app, and I'm
not sure who to blame for it (tapestry, hibernate, or me). The scenario is
as follows:

    I'm using a form to edit data from a User entity having these three
particular attributes:


    Role is an enum, while Organization and Project are both entities. There
are three roles: superadmin, admin and user. A superadmin belongs to no
organization, so its organization attribute is set to null. Only users (i.e.
neither superadmins nor admins) have projects assigned to them.

    "role" and "organization" are chosen through <select> objects, and
"projects" are selected in a <checklist> component. When I select a role
item, both organization and projects zones are updated, while selecting an
organization triggers a projects' zone update only. The projects zone must
be displayed only when the role is "user".

EditUser.tml:


EditUser.java (solution 1):


    Now suppose I want to change a user's role from admin to superadmin.
Organization and projects zones get correctly updated (with organization
being set to null), but when I hit the submit button, I can see the user
object has been "reloaded" (the debugger shows its memory id has changed),
and while "role" holds the new value, "organization" is reverted back to its
pre-null value, thus incorrect data being persisted.

    I kind of solved this by eliminating the @PageActivationContext
annotation and using an onActivate() method to keep the session-persisted
user object:

EditUser.java (solution 2):


    But in this case, I get a new error.

    A bit of information, first. The Organization entity has itself a
"projects" attribute too:


    I need to read this attribute in order to decide if the projects zone
must be displayed or not (you can't assign projects to a user if the
organization he or she belongs to has no projects at all).

    The three User's attributes are fetched EAGERly.

    Now, when changing the user's role from "admin" to "user", the projects
zone should be displayed to let me choose projects to be assigned to the
user. Instead I see an Ajax error message:

"Ajax failure: Status 500 for /app/user/edit.role:change: Render queue error
in BeginRender[user/Edit:delegate_1]: Failure reading parameter 'to' of
component user/Edit:delegate_1: failed to lazily initialize a collection of
role: [...].entities.Organization.projects, no session or session was
closed"

    And actually, the user.organization.projects field has a null hibernate
session property value. I guess that error message is due to the fact that
the Organization's projects attribute has no annotated fetch type, and,
seemingly, hibernate uses the LAZY one by default. But I can't set that
fetch type to EAGER, since otherwise I get a MultipleBagFetchException from
hibernate.

    Now if you've read up to this point I'd surely vote you for president.
But before that... any ideas on how to keep the user object contents using
solution 1, or to avoid the hibernate exception in solution 2?

    Thanks (a lot) in advance.


--
View this message in context: http://tapestry.1045711.n5.nabble.com/Multizone-updating-and-hibernate-session-loss-tp4936102p4936102.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Multizone updating and hibernate session loss

Posted by Greendog <ma...@gmail.com>.
Thiago H de Paula Figueiredo wrote:
> 
> Hi!
> 
> This is actually a mailing list, not a forum, but Nabble and maybe some  
> other sites do provide a forum interface over the mailing list. :)
> 

You're right. I was using Nabble's. 


Thiago H de Paula Figueiredo wrote:
> 
>> EditUser.java (solution 1):
> 
> I can't see the source. Am I the only one?
> 

I just included a field and a couple of event managers in my message, trying
not to make it too extense. I guess I omitted relevant parts, so here is the
full page class source code:



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Multizone-updating-and-hibernate-session-loss-tp4936102p4936906.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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