[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5014) Custom PropertyAccessor / illegal access to loading collection
Stephan Sann (JIRA)
noreply at atlassian.com
Tue Mar 16 05:06:50 EDT 2010
Custom PropertyAccessor / illegal access to loading collection
--------------------------------------------------------------
Key: HHH-5014
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5014
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.2
Environment: Hibernate 3.3.2 GA, HSQLDB 2.0.0-rc8
Reporter: Stephan Sann
I posted the problem on the Hibernate-forum (https://forum.hibernate.org/viewtopic.php?f=1&t=1003277) and got no answer. So I assume this is a bug.
I wrote a custom PropertyAccessor
{code}
public class MyPropertyAccessor implements PropertyAccessor{code}
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{code}
What I get during runtime is a "LazyInitializationException: illegal access to loading collection" (Stacktrace see below.).
IMHO Hibernate shouldn't 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!)
If I don't got the concept of a PropertyAccessor completely wrong, the "set"-flow should work like this:
1.) (Hibernate-Core) Load the data from Database (completely*), transform it to a value of the matching type (e.g. List) and hand it over to the PropertyAccessor.
2.) (PropertyAccessor) Receive the (completely*) loaded and transformed value, do whatever modification is necessary and set the result to the entity.
completely*: In case of FetchType.EAGER: Completely loaded / in case of FetchType.LAZY: "Ready to access".
Correct me if I got something wrong here.
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;{code}
(and the Hibernate-session should also be alive at the moment of the Exception)
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...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list