How to keep an Hibernate's Session open until the page is rendered
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;
开发者_Go百科 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
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.
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.
精彩评论