anthony wrote:
be sure to understand what detached object mean.
1- you get your object from a session --> all is fine, lazy will work
2- you close the session --> bug if you try to access a lazy loaded propety --> your object is detached
3- if you open a new session, be sure to reattach the object by calling session.update or session.lock --> that's why your case is working.
Managing your session is the most important
PS: i don't have time to read your java code, so i can be wrong...
1a - i create the object ut in lets call it A.Class and store it in a static var
Code:
static Utilizador oUtilizador;
//...
String query = "SELECT ut from Utilizador as ut "
+ "WHERE ut.palavraPasse = :palavraPasse "
+ "AND ut.nomeUtilizador = :nomeUtilizador "
+ "AND ut.relatorio.turma.q1 = :epocaActual";
Query q = sess.createQuery(query);
q.setString("palavraPasse", palavraPasse);
q.setString("nomeUtilizador", nomeUtilizador);
q.setInteger("epocaActual", epocaActual);
List lista = q.list();
for (int i = 0; i < lista.size(); i++) {
ut = (Utilizador) lista.get(i);
if (lista.size() > 0) {
//...
oUtilizador = ut;
//...
1b - then, in B.class i make
Code:
utlizador = A.oUtilizador;
Iterator iter2 = ut.getRelatorio().getTurma().getQ22DiscAl().iterator();
while (iter2.hasNext()) {
visual.lmQ22Disc.addElement(iter2.next());
}
In the meanwhile i'm certain no session was closed!
So to Anthony's point #3, i only had to open a new session in order to re.atach, because i figure i allready had (allways) an opened session...
Perhaps with this treatment i use i no longer have a session (at least one that's associated with my ut object)
So i understand Pascal's saying:
Quote:
the Object containing the lazy collection needs to be associated with a session. so just having 'an' open session is not good enough.
Right?
thanks a lot to both for helping me!