Hi,

When i was clicking through my app i say hibernate errors like session is invalid (the hibernate session) or transient objects error when updating objects.
These kind of things happens when i use hibernate objects that are read in another thread/hibernate session (another http request)
but this shouldn't be possible... Because i use detacheable models all over the place. So i at sometime the deattach is not called.


I have found the place where it doesn't happen:

HttpRequestCycle.callComponentListener()

When a interface method is called then that method could trigger a model attach.. And that method could set the next page i want to go to..
So after the call:
method.invoke(component, new Object[] { });


the getPage() of requestCycle can point to another page then the page where the method was invoked on.
But afte callComponentListener we only work with that page so the deattach models are never called for the page we just called the interface method on.
And i do return to that page in a link on the page. So after that the page has still attached models with wrong hibernate objects for that session.


So i made a fix in .callComponentListener()

// Set form component values from cookies
setFormComponentValuesFromCookies(page);
// Test if the current page is also the next page.
if(getPage() != page)
{
// if it is not the same then do call deattach models to deattach any models that can be loaded by the
// component listener
deattachModels(page);
}
return true;


(between setFormComponentValuesFromCookies and the return true)

So when the page that is used for the component listener is not the page where the render will work on i will call deattachModels..

But when i debugged that i stumbled on something else:

Component:
final void detachModels(final Page page)
{
page.visitChildren(new IVisitor()
{
public Object component(final Component component)
{
IModel componentModel = component.getModel();
if ((componentModel != null) && (componentModel instanceof IDetachableModel))
{
((IDetachableModel)componentModel).detach();
}


this component.getModel() call can trigger an attach that is then directly detached again..
For example if a component from a form that is a propertymodel that has the main model of the form itself is deattached
and it is not attached yet then it will attach itself AND it will attached the form model again that was right before that deattached
through its own Form component..


so i think we should call component.getModel() but make a method in component besides the current detachModels(page)
a detachModel(). Where we test if the model instanceof IDetachableModel and then call detach itself.. So that we never go through the getModel()..
(which triggers an attach call)


any objections?

johan




------------------------------------------------------- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl _______________________________________________ Wicket-develop mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/wicket-develop

Reply via email to