-->
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: LazyInitializationException - need help
PostPosted: Thu Nov 03, 2005 2:24 am 
Newbie

Joined: Fri Sep 30, 2005 12:45 am
Posts: 8
I am getting the below exception when I try to set the parent reference for a collection in the setter of the collection in Parent.

If I don't propagate the parent reference to the child objects, the parent is not set on the child objects and I get a null pointer exception.
Please advice.

public void setPersonalInformationInsurance(Set personalInformationInsurance) {
if(personalInformationInsurance != null){
propagateParentReferenceToInsurances(personalInformationInsurance.iterator());
}
this.personalInformationInsurance = personalInformationInsurance;
}

private void propagateParentReferenceToInsurances(Iterator personalInformationInsurances) {
while (personalInformationInsurances.hasNext()) {
PersonalInformationInsurance insurance = (PersonalInformationInsurance)personalInformationInsurances.next();
insurance.setPersonalInformation(this);
}
}
<set
name="personalInformationInsurance"
lazy="true"
inverse="true"
cascade="all,delete-orphan"
>
<key>
<column name="PERSONAL_INFORMATION_ID_SEQ" />
</key>
<one-to-many
class="gov.va.med.domain.model.PersonalInformationInsurance"
/>
</set>

////////////

<!-- bi-directional many-to-one association to PersonalInformation (Parent)-->
<many-to-one
name="personalInformation"
class="gov.va.med.domain.model.PersonalInformation"
not-null="true"
>
<column name="PERSONAL_INFORMATION_ID_SEQ" />
</many-to-one>

////Exception //////////////////////////////////////////////////////////////////////

org.hibernate.PropertyAccessException: Exception occurred inside setter of gov.va.med.domain.model.Cytology.cytologySpecimens
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:51)
at org.hibernate.tuple.AbstractTuplizer.setPropertyValues(AbstractTuplizer.java:207)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:176)
at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
at org.hibernate.loader.Loader.doQuery(Loader.java:436)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at gov.va.med.domain.persistence.util.HibernateTableLoader.getRows(HibernateTableLoader.java:119)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:661)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)

Caused by: org.hibernate.LazyInitializationException: illegal access to loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:172)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
at gov.va.med.domain.model.Cytology.setCytologySpecimens(Cytology.java:151)
... 112 more


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 9:15 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
You are accessing a proxy outside its session.

It's hard to tell what is cousing this problem without further information. My guess is that either you have a problem with your session management, or your passing around unitialized proxies as transfer objects.

You can switch of proxys in you hbm.xml file or initialize them explicitely with
Code:
Hibernate.initialize()


HTH
Ernst


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.