-->
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.  [ 1 post ] 
Author Message
 Post subject: Custom PropertyAccessor / illegal access to loading collecti
PostPosted: Mon Mar 15, 2010 6:02 am 
Newbie

Joined: Thu Jan 08, 2009 8:21 am
Posts: 5
Hibernate-Version: 3.3.2 GA

Hello all,

since Google responses nothing (!) to:
"org.hibernate.LazyInitializationException: illegal access to loading collection" PropertyAccessor

...and only searching for the Exception leads me nowhere, I would like to ask for help with my problem here.

I wrote a custom PropertyAccessor
Code:
public class MyPropertyAccessor implements PropertyAccessor


with this code within the set-Method of the Setter:
Code:
        public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException {
            try {

                if (((List) value) == null) {
                    return;
                }

                List tempList = new ArrayList();
                tempList.addAll((List) value);

                // ... more code here


What I get during runtime is a "LazyInitializationException: illegal access to loading collection" (Stacktrace see below.).

Why does Hibernate give me an uninitialized value (AbstractPersistentCollection) into the set-method of the PropertyAccessor? (Hibernate should assume that I want to do something with the collection before setting it to the entity!)

BTW: The corresponding List-property of the Entity is FetchType.EAGER:
Code:
    @OneToMany (fetch = FetchType.EAGER)
    @Cascade ({CascadeType.ALL})
    @JoinColumn(name="ParentId")
    @IndexColumn(name="ParentIndex")
    @AccessType(value="path.to.MyPropertyAccessor")
    private List<Foo> fooList;


(and the Hibernate-session should also be alive at the moment of the Exception)

What can I do to prevent this?

Thank you very much in advance for any hint!

Best regards
lotk

The stacktrace:
org.hibernate.LazyInitializationException: illegal access to loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:363)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentList.toArray(PersistentList.java:146)
at java.util.ArrayList.addAll(ArrayList.java:472)
at path.to.MyPropertyAccessor$BasicSetter.set(MyPropertyAccessor.java:71)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:352)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:232)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3580)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:152)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877)
at org.hibernate.loader.Loader.doQuery(Loader.java:752)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1885)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3062)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:906)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:843)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:836)
at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:519)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:512)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:506)
// some more...


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

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.