-->
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: illegal access to loading collection
PostPosted: Sun Apr 11, 2010 4:06 pm 
Newbie

Joined: Wed Jul 26, 2006 4:18 pm
Posts: 8
Location: Brussels, Belgium
I have a threesome relation :
A Configuration has zero or many Company defined
A Company has zero or many Users defined.
A User is only defined in one Configuration.
All relations are bi-directionnal !

Code:
  _________                                      ___________
|          |                                  /|           |
|  Config  | ----------------------------------| Company   |
|__________|                                  \|___________|
             \                                         |
              \                                        |
               \_                                      |
                |\                                     |                       
                      ____________                     | 
                     |            |\                   |
                     |    User    |------------------
                     |____________|/

Now my problem.
In my unit test, I retrieve a fake config from the DB and try to attach it Companies & Users.
My code does more or less this :
Code:
cfg = Utility.retrieveTestCfg();  // Retrieve a test data from the DB. OK !
tx = session.beginTransaction();
usr = new User("first", "last", ...); // Create a new user. OK !
cpy = new Company("Name", "Street", "City", ...); // Create a new Company. OK !
usr.setCompany(cpy);
usr.setConfig(cfg);
cpy.setConfig(cfg);

This works perfectly when I don't save or when I use newly created instances (line 1 : cfg = new Config("key1", "key2", ...);).
Now, if I do
Code:
session.saveOrUpdate(usr);

I get an exception "while setting Company.Config ..."
If I do
Code:
session.saveOrUpdate(cpy);

I get an exception "while setting User.Config ..."

I don't even have the time to call on the transaction to commit or the sessionto flush ... the exception is thrown before.

:(
This works fine when doing this with newly created instances and persisting them !
All links are lazy (so far).
Choosing a fetch strategy of "join" or "select" does not help.
Would someone have an hint for me ?

tx,

\T,

Full stack trace :
Quote:
org.hibernate.PropertyAccessException: Exception occurred inside setter of my.dotcom.project.dao.CompanyTo.Connector
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:65)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:200)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3566)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:797)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:241)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.loader.entity.BatchingEntityLoader.load(BatchingEntityLoader.java:82)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at my.dotcom.project.util.TestToolBox.getSapRfcConnectorPersistedTestInstance(TestToolBox.java:52)
at my.dotcom.project.dao.UserDaoTest.check2UsersPersistendedInstancesAreNeverIdentical(UserDaoTest.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
... 55 more
Caused by: org.hibernate.LazyInitializationException: illegal access to loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.AbstractPersistentCollection.readElementExistence(AbstractPersistentCollection.java:142)
at org.hibernate.collection.PersistentSet.add(PersistentSet.java:187)
at my.dotcom.project.dao.CompanyTo.Connector(CompanyTo.java:660)
... 60 more



Top
 Profile  
 
 Post subject: Re: illegal access to loading collection
PostPosted: Wed Apr 14, 2010 5:26 am 
Newbie

Joined: Wed Jul 26, 2006 4:18 pm
Posts: 8
Location: Brussels, Belgium
This problem in my case was related to 2 typo's in the Configuration.
Twice, the "id" in the Java code was typed "Id".
What hint me in the right direction ?
Here is more or less what Hibernate was executing :
Quote:
Hibernate: select users0_.CONFIG_ID as CONFIG64_3_, users0_.USER_ID as USER1_3_, users0_.USER_ID as USER1_2_2_, users0_.FieldOne as FieldOne2_2_ ...

The fact that it fetch twice the field USER_ID was annoying me for a while but ... it is only when I did a little piece of code without any link to the legacy I have to map that I realised that this behavior was not the default one ... (+ it was working there --> no bug in Hibernate).
I hope it helps someone else :)
\T,


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.