-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate 2.16 lazy problem
PostPosted: Fri Feb 03, 2006 8:29 am 
Newbie

Joined: Thu Jan 26, 2006 2:45 pm
Posts: 5
Hi, I'm newbie at Hibernate but I got into a project that already was working with JBoss 3.2.3 and Hibernate 2.16.

The application was designed to use Hibernate with lazy="false" (default for Hibernate 2.1.6), but the problem is that it loads lots of data that we don't need for all sitations. For example it loads, all roles and it assosiated objects of a User, when we only need (in some case) just the User itself!

So we tried to use the option lazy="true", but... When I am in a big transaction => Hibernate close the session!! and it throws one of those LazyInitializeException...

My code is something like this:

Session session = ThreadLocalSession.currentSession();

// Obtengo el usuario por login
SecurityServices secServices = new SecurityServicesBusinessDelegate();
User user = secServices.getUser(userLogin);
if (user == null) { // No se encontró el usuario
return ret;
}

// Obtengo los registros de estado de un incidente no terminados
List status = getOpenIncidentStatusByUser(user.getId());

// Obtengo los incidentes en revision (por parte de un administrador) ingresados por el usuario
//TODO: Estudiar si es necesario
List inRevision = getIncidentStatusInRevision(user);
if (inRevision != null && inRevision.size() > 0) {
status.addAll(inRevision);
}

Date currentDateTime = DateUtilities.getCurrentDateTime();
Date currentDate = DateUtilities.getCurrentDate();

// Recorro los estados armando los registros de resumen
// correspondientes
Iterator itStatus = status.iterator();
while (itStatus.hasNext()) {
IncidentStatus incStatus = (IncidentStatus) itStatus.next();

long incidentCode = incStatus.getIncident();
long subincidentCode = incStatus.getSubincident();

// Obtengo el ultimo registro de incidente asociado a este estado
IncidentFixedData fixedData = getIncidentFixedData(incidentCode, subincidentCode, false);

// Obtengo el último registro de traza del incidente
IncidentTrace trace = getIncidentTrace(incidentCode, subincidentCode);
IncidentTrace firstTrace = trace;
if (trace.getAction() > 1) {
firstTrace = getFirstIncidentTrace(incidentCode, subincidentCode);
}

// Obtengo los datos para el resumen
long incidentId = fixedData.getId();
String description = fixedData.getDescription();
HERE IT HANGS=> String statusDsc = incStatus.getStatus().getDescription();
String priority = fixedData.getPriority().getDescription();
Date predictedDate = incStatus.getPredictedDate();
Date commitedDate = incStatus.getDateOfCommitment();
Date deadline = incStatus.getDeadline();
String type = fixedData.getFormType().getName();
String recomendation = trace.getRecomendation();

FormTypeOperation formTypeOper = trace.getFormTypeOperation();

int color = IncidentSumary.COLOR_GREEN;
if (DateUtilities.compare(predictedDate, currentDateTime) >= 0) {
color = IncidentSumary.COLOR_RED;
} else {
int daysNotification = fixedData.getSubMotive().getDaysNotification();
Date temp = DateUtilities.addDays(predictedDate, -daysNotification);
if (DateUtilities.compare(temp, DateUtilities.getCurrentDateTime()) >= 0) {
color = IncidentSumary.COLOR_YELLOW;
}
}

// Creo y agrego el registro de resumen a la lista
long priorityId = fixedData.getPriority().getId();
int lastAction = trace.getAction();
String motive = fixedData.getSubMotive().getGroupMotiveContactType().getMotive();
String submotive = fixedData.getSubMotive().getDescription();
String group = fixedData.getSubMotive().getGroupMotiveContactType().getGroup().getDescription();
String assignedTo = trace.getStatus().getAssignedTo().getName();
String supervisor = trace.getStatus().getSupervisor().getName();
ret.add(new IncidentSumary(incidentId, description, statusDsc, priority, predictedDate, commitedDate, type, recomendation, formTypeOper, incidentCode, subincidentCode, priorityId, color, lastAction, motive, submotive, group, firstTrace.getDateTime(), assignedTo, supervisor));
Collections.sort(ret);
}

And My XMLs:

IncidentStatus.hbm.xml:
..
<class name="uy.com.isbel.crmop.incidents.vo.IncidentStatus" table="FRM_INCIDENTES_ESTADOS" lazy="true">
<id type="long" name="id" column="ID" unsaved-value="-1">
<generator class="sequence">
<param name="sequence">CRMOP_INCESTADOS_SQ</param>
</generator>
</id>
<property type="long" name="idFormType" column="IDFORMULARIO" />
<property type="long" name="incident" column="CODINCIDENTE" />
<property type="long" name="subincident" column="CODSUBINCIDENTE" />
..
<many-to-one name="assignedTo" cascade="none">
<column name="ASIGNADOA"/>
</many-to-one>

<many-to-one name="supervisor" cascade="none">
<column name="IDSUPERVISOR"/>
</many-to-one>

<many-to-one name="status" cascade="none">
<column name="IDESTADO"/>
</many-to-one>

<many-to-one name="priority" cascade="none">
<column name="IDPRIORIDAD"/>
</many-to-one>
..
</class>
..
IncidentFixedData.hbm.xml:
..
<class name="uy.com.isbel.crmop.incidents.vo.IncidentFixedData" table="FRM_INCIDENTES_DATOS_FIJOS" lazy="true">
<id type="long" name="id" column="ID" unsaved-value="-1">
<generator class="sequence">
<param name="sequence">CRMOP_INCDFIJOS_SQ</param>
</generator>
</id>
<property type="long" name="incident" column="CODINCIDENTE" />
<property type="long" name="subincident" column="CODSUBINCIDENTE" />
...
<many-to-one name="channel" cascade="none">
<column name="IDCANAL"/>
</many-to-one>

<many-to-one name="formType" cascade="none">
<column name="IDFORMULARIO"/>
</many-to-one>

<many-to-one name="user" cascade="none">
<column name="IDUSUARIO"/>
</many-to-one>

<many-to-one name="client" cascade="none">
<column name="IDCLIENTE" />
</many-to-one>

<many-to-one name="contact" cascade="none">
<column name="IDCONTACTO" />
</many-to-one>

<many-to-one name="subMotive" cascade="none">
<column name="IDSUBCAT" />
</many-to-one>

<many-to-one name="priority" cascade="none">
<column name="PRIORIDAD"/>
</many-to-one>
...
</class>
..

User.hbm.xml
..
<class name="uy.com.isbel.crmop.security.vo.User" table="Usuarios" lazy="true">
<id name="id" type="long" column="IdUsuario" unsaved-value="-1">
<generator class="sequence">
<param name="sequence">USUARIOS_SQ</param>
</generator>
</id>

<property name="login" column="Nombre" type="string"/>
<property name="email" column="Email" type="string"/>
<property name="name" column="DESCRIPCION" type="string"/>
...
</class>
..

Status.hxm.xml
<class name="uy.com.isbel.crmop.incidents.vo.Status" table="ESTADOS" lazy="true">
<id type="long" name="id" column="IDENTIFICADOR" unsaved-value="-1">
<generator class="sequence">
<param name="sequence">CRMOP_ESTADOS_SQ</param>
</generator>
</id>
<property type="string" name="description" column="DESCRIPCION" />
</class>

Any help, will be appretiated.

Thank you ver much.
Marcelo

_________________
Computer Engineering Marcelo Giorgi.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 8:49 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
If your services are local then simplest way to refactor this application is to remove all "close and commit" calls and to use filter like this http://www.hibernate.org/43.html (there are no simple ways to refactor this stuff for remote services). Application code closes session, hibernate doe's not close session itsef.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 12:24 pm 
Newbie

Joined: Thu Jan 26, 2006 2:45 pm
Posts: 5
The funny think, is that I don't have any commit or close statement in that portion of code.. I think it have something to do with the amount of data retrieved or the amount of joins that Hibernate have to do for that code. Because If i comment the port of the code which looks like this:

// Obtengo el usuario por login
SecurityServices secServices = new SecurityServicesBusinessDelegate();
User user = secServices.getUser(userLogin);
if (user == null) { // No se encontró el usuario
return ret;
}


Then, It works...why Hibernate would behave like that ?

_________________
Computer Engineering Marcelo Giorgi.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.