Thank you all for your answers. Currently, I don't have enough time to implement the solution that you suggest, that is: implement some Session bean methods that have some properties initialized and others don't. For example:
I) User getSkeletonUser(String login) {
..
Query q = session.createQuery("from User login=?");
q.setString(0, login);
return (User) q.uniqueResult();
}
II) User getCompleteUser(String login) {
..
Query q = session.createQuery("from User login=?");
q.setString(0, login);
User u = (User) q.uniqueResult();
//initialize related data
u.getUserRoles();
..
return (User)q.uniqueResult();
}
At the moment, I had the first approach implemented with lazy="false". In such a way the hole object where retrieved, but it implies a very poor performance.
The other alternative that I am evaluating is don't use Session Beans so the methods above were implemented in the same way as the first approach but in a plain java object (using the session-per-request) pattern that enables the use of lazy feature of Hibernate.
Then again, I'm having some troubles, I set all the object with the lazy flag, so they would be retrieved only when they are needed. But I think there is a maximum size of the transaction handled, because I get an error (own Session was closed) while a i am iterating over a collection of Hibernate proxy objects. The strange thing is that I obtained the error in the n"th" iteration, that means, i think, that there is some transaction size problem...I don't know if i am right about this..
Thank you soy much for ANY help.
Marcelo
_________________ Computer Engineering Marcelo Giorgi.
|