-->
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.  [ 2 posts ] 
Author Message
 Post subject: Lazy Initialization
PostPosted: Thu Dec 08, 2005 4:08 pm 
Newbie

Joined: Thu Dec 08, 2005 3:51 pm
Posts: 1
I´m using the Hibernate version 3.0.5

One of my mapping files is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-cascade="none">
<class name="com.embratel.confserv.order.domain.ServiceTypeImpl" table="SERVICE_TYPE" dynamic-insert="false" dynamic-update="false">
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="ID" sql-type="NUMBER(19)"/>
<generator class="sequence">
<param name="sequence">SERVICE_TYPE_SEQ</param>
</generator>
</id>
<property name="type" type="java.lang.String">
<column name="TYPE" not-null="true" unique="true" sql-type="VARCHAR2(255)"/>
</property>
<property name="queueName" type="java.lang.String">
<column name="QUEUE_NAME" not-null="true" unique="false" sql-type="VARCHAR2(255)"/>
</property>
<set name="translators" order-by="SERVICE_TYPE_FK" lazy="true" fetch="select" inverse="false">
<key foreign-key="TRANSLATOR_SERVICE_TYPE_FKC">
<column name="SERVICE_TYPE_FK" sql-type="NUMBER(19)"/>
</key>
<one-to-many class="com.embratel.confserv.order.domain.TranslatorImpl"/>
</set>
<set name="validators" order-by="SERVICE_TYPE_FK" lazy="true" fetch="select" inverse="false">
<key foreign-key="VALIDATOR_SERVICE_TYPE_FKC">
<column name="SERVICE_TYPE_FK" sql-type="NUMBER(19)"/>
</key>
<one-to-many class="com.embratel.confserv.order.domain.ValidatorImpl"/>
</set>
</class>
</hibernate-mapping>


My class is like this:
package com.embratel.confserv.order.domain;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.LockMode;
import com.embratel.confserv.domain.AbstractDAO;

/**
*
*/
public abstract class ServiceType
extends com.embratel.confserv.domain.AbstractEntity implements java.io.Serializable
{



/**
* The serial version UID of this class. Needed for serialization.
*/
private static final long serialVersionUID = 2948988219572588067L;

private java.lang.String type;

... getter and setter for type

private java.lang.String queueName;

... getter and setter for queueName

private java.lang.Long id;

... getter and setter for id

private java.util.Collection translators = new java.util.HashSet();

/**
*
*/
public java.util.Collection getTranslators()
{
Session session = AbstractDAO.currentSession();
if(getId() != null) {
//session.saveOrUpdate(this);
//session.lock(this, LockMode.NONE);
Hibernate.initialize(this.translators);
}
//session.flush();
AbstractDAO.closeSession();
return translators;
}

public void setTranslators(java.util.Collection translators)
{
this.translators = translators;
}

private java.util.Collection validators = new java.util.HashSet();

/**
*
*/
public java.util.Collection getValidators()
{
Session session = AbstractDAO.currentSession();
if(getId() != null) {
//session.saveOrUpdate(this);
//session.lock(this, LockMode.NONE);
Hibernate.initialize(this.validators);
}
//session.flush();
AbstractDAO.closeSession();
return validators;
}

public void setValidators(java.util.Collection validators)
{
this.validators = validators;
}

}


I get the persistent object via this way:
public ServiceType selectByType(String serviceType) throws DAOException {
Session session = null;
try {
session = currentSession();

org.hibernate.Query qry = session
.createQuery("from com.embratel.confserv.order.domain.ServiceType st where st.type = ?");
qry.setString(0, serviceType);
List res = qry.list();
Iterator it = res.iterator();
if (it.hasNext()) {
ServiceTypeImpl next = (ServiceTypeImpl) it.next();
return next;
}
throw new DAOException("Não foi encontrado um tipo de serviço '"
+ serviceType + "'");

} catch (HibernateException h) {
throw new DAOException(h);
} finally {
try {
closeSession();
} catch (HibernateException e) {
throw new DAOException(e);
}
}
}

I have a class that has a association one-to-many for another. When I get the first class, I don´t have the second yet (because of lazy initialization). When I try to get the second, I use the initialize method but using another session. And then, I got the error:

17:33:09,796 INFO [STDOUT] com.embratel.confserv.order.service.ServiceManagerException: org.hibernate.HibernateException: disconnected session

When I try to use the methods lock OR saveOrUpdate to associate the object to the session, I got the error:

16:48:17,687 INFO [STDOUT] javax.ejb.TransactionRolledbackLocalException: Unexpected Error
java.lang.OutOfMemoryError: Java heap space
; CausedByException is:
Unexpected Error
java.lang.OutOfMemoryError: Java heap space

Anybody can help me, please?
Thanks in advance,
Luciana.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 4:22 pm 
Regular
Regular

Joined: Tue Oct 28, 2003 8:25 am
Posts: 72
Location: Belgium
There could be different causes to your problem.

First I would look at how many objects is your query loading in memory and what the max heap size of the JVM is.

Also, could you show the code you're using to reattach objects to the session ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.