views:

58

answers:

2

I'm having the following problem:

  • I'm using Oracle ADF for the view and controller of my app.
  • With OpenSessionInViewFilter, I intercept the request and open an Hibernate's Session, and it is closed as soon as the bean's method finishes.

What I need is to keep the Session opened until the page is rendered, because in my JSP y use the lazy attributes of the object i load from the DB.

For example:

When I enter index.jspx the IndexBean#main() is executed:

public class IndexBean{
    private DBObject myDBObject;
    public String main(){
        this.myDBObject = this.myDAO.loadObjectFromDB();
        return null;
    }
}

in index.jspx I have:

...
<af:inputText value="#{myDBObject.lazyAttribute}" />
...

I'd like that the Hibernate's Session keeps open until the af:inputText is processed.

Is this possible? How?

Thanks in advance

A: 

I'd suggest you keep your view decoupled from your model and eliminate the lazy loading. Give the page all the data it needs before it gets rendered. If fetching the additional data is really a big performance hit, then consider re-designing the app to present that data separately.

TMN
The presentation of the data it is not my desition, is the client's.Eliminate the lazy loading it is not an option.My view it is decoupled, for the view should be transparent if the attribute it was loaded before or at that moment... the af:inputText only calls the getMyDBObject().getLazyAttribute() and expects the value. If the value was loaded, it returns the value, otherwise it should ask for it to the model...
Neuquino
@Neuquino you are wrong, the getter getLazyAttribute() is not a simple getter for internal variable, it uses some unexpected dependency, so your object can't be passed to different tier, because that dependency won't exist there. If you would like to continue writing with 2 tier design, that's ok but you should know all the problems you'll face (especially when somebody else - the client writes the presentation layer). To fix it for two tier, just make sure OpenSessionInViewFilter works.
Vitaly Polonetsky
If your view is asking the database for data, it's not decoupled. It can't "live on its own", so to speak -- it depends on the database (which lives in another tier).
TMN
A: 

Finally, I solved my problem.

The OpenSessionInViewFilter it was working right.

There was a problem with the <af:table> component I was using... The weird thing was that the <af:table> creates a new request. This new request was closing and creating a new Hibernate Session.

Neuquino
The issue with the af:table component is solved adding the following attribute: contentDelivery="immediate"
Neuquino