Hi! I hope this question deserve your attention and answer.
I got the following secuence:
- Open my session
- Get a list of objects using lazy loading
- Close the Session
The user pick one of those objects.
I try to load the pending objects (those ones related to this by many-to-one mapping) using the follwing code:
Code:
public void resolveLazyLoading(Object o){
Ccliente c=(Ccliente)o;
Session s = null;
try {
s = getSession();
s.lock(c,LockMode.NONE);
Integer cd=(c.getIddireccionbodega()!=null)?c.getIddireccionbodega().getIddireccion():null;
cd=(c.getIddireccionfiscal()!=null)?c.getIddireccionfiscal().getIddireccion():null;
c.getIddireccionoficina().getIddireccion();
c.getIdempleado().getIdempleado();
c.getIdsucursal().getIdsucursal();
} catch (HibernateException e){
e.printStackTrace();
}finally {
try {
closeSession();
} catch (HibernateException e1) {}
}
}
Then When I try to use the object's properties, say
c.getIddireccionoficina().getIddireccion();, I get the following error:
Code:
11:03:51,046 ERROR LazyInitializer:63 - Exception initializing proxy
net.sf.hibernate.HibernateException: Could not initialize proxy - the owning Session was closed
at net.sf.hibernate.proxy.LazyInitializer.initialize(LazyInitializer.java:47)
at net.sf.hibernate.proxy.LazyInitializer.initializeWrapExceptions(LazyInitializer.java:60)
at net.sf.hibernate.proxy.LazyInitializer.getImplementation(LazyInitializer.java:164)
at net.sf.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:108)
at net.sf.hibernate.proxy.HibernateProxy$$EnhancerByCGLIB$$61ab85cc.toString(<generated>)
at com.ia.ventas.ui.UIPedidoDetalle.muestraCliente(UIPedidoDetalle.java:1043)
at com.ia.ventas.ui.UIPedidoDetalle.inicializaVentana(UIPedidoDetalle.java:875)
at com.ia.ventas.ui.UIPedidoDetalle.createDialogArea(UIPedidoDetalle.java:803)
at org.eclipse.jface.dialogs.Dialog.createContents(Dialog.java:632)
at org.eclipse.jface.window.Window.create(Window.java:348)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:925)
at org.eclipse.jface.window.Window.open(Window.java:637)
at com.ia.ventas.ui.UIPedido.agregaPedido(UIPedido.java:549)
at com.ia.ventas.ui.UIPedido.access$2(UIPedido.java:536)
at com.ia.ventas.ui.UIPedido$6.widgetSelected(UIPedido.java:224)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2772)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2431)
at com.ia.Menu.main(Menu.java:112)
My question is I have to keep the session open all the time even when I already use those object's properties and supposedly they already loaded their state from database?
Thanks in advance!!
Rodolfo