-->
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.  [ 6 posts ] 
Author Message
 Post subject: Null pointer when loading child at 3:rd level
PostPosted: Sat Mar 04, 2006 5:49 am 
Beginner
Beginner

Joined: Sun Feb 19, 2006 5:13 am
Posts: 22
Hi

I have a problem with Hiberntae when doing the following.

I have a Swing client whch has a parent /child structure (Using JTree). When I add a new chld I send the id over to the server of the parent and a new child to add to it. On the server I first load the parent using session.load and I then add the child using parent.add(child). I have the following mapping for the parent child relationship:

Code:
<set name="categories" inverse="true" cascade="all" batch-size="3" fetch="join" lazy="false">
            <key column="parentId"/>
            <one-to-many class="se.so4it.dam.api.category.CategoryImplementation"/>
        </set>
        <many-to-one name="parent" column="parentId" not-null="false" class="se.so4it.dam.api.category.CategoryImplementation" fetch="join" lazy="false"/>


The strange thing is that it works nicely down to the second level but when I try it on the 3:rd level I get a null pointer exception. I done some tracing and I notice that it happens when Hibernate is trying to do
Code:
Loader.doQueryAndInitializeNonLazyCollections


I was just wonderig if this is somethng obvious wrong I done or if it is a problem i Hibernate that I need to report?

Magnus


Top
 Profile  
 
 Post subject: Re: Null pointer when loading child at 3:rd level, URGENT!
PostPosted: Sun Mar 05, 2006 5:10 am 
Beginner
Beginner

Joined: Sun Feb 19, 2006 5:13 am
Posts: 22
I have a very iritating problem with Hibernate when doing the following.

I have a Swing client whch has a parent /child structure (Using JTree). When I add a new child I send the id over to the server of the parent and a new child to add to it. On the server I first load the parent using session.load and I then add the child using parent.add(child). I have the following mapping for the parent child relationship:

Code:
<set name="categories" inverse="true" cascade="all" batch-size="3" fetch="join" lazy="false">
            <key column="parentId"/>
            <one-to-many class="se.so4it.dam.api.category.CategoryImplementation"/>
        </set>
        <many-to-one name="parent" column="parentId" not-null="false" class="se.so4it.dam.api.category.CategoryImplementation" fetch="join" lazy="false"/>


The strange thing is that it works nicely down to the second level but when I try it on the 3:rd level I get a null pointer exception. I done some tracing and I notice that it happens when Hibernate is trying to do
Code:
Loader.doQueryAndInitializeNonLazyCollections


I was just wonderig if this is somethng obvious wrong I done or if it is a problem i Hibernate that I need to report?



Ok this is the exception thrown

Code:
09:53:49,390 INFO  [DefaultLoadEventListener] Error performing load command
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.bytecode.use_reflection_optimizer=false for more info) setter of se.so4it.dam.api.category.CategoryImplementation.setParent
        at org.hibernate.bytecode.cglib.AccessOptimizerAdapter.setPropertyValues(AccessOptimizerAdapter.java:60)
        at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:214)
        at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:188)
        at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3398)
        at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:126)
        at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
        at org.hibernate.loader.Loader.doQuery(Loader.java:717)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
        at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
        at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
        at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
        at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2876)
        at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
        at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
        at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
        at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:161)
        at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
        at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
        at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:830)
        at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
        at org.hibernate.type.EntityType.resolve(EntityType.java:303)
        at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
        at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
        at org.hibernate.loader.Loader.doQuery(Loader.java:717)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
        at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
        at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
        at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
        at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2876)
        at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
        at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
        at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
        at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:161)
        at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
        at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
        at org.hibernate.impl.SessionImpl.load(SessionImpl.java:770)
        at se.so4it.dam.server.category.CategoryDaoImplementation.loadCategory(CategoryDaoImplementation.java:87)
        at se.so4it.dam.server.category.interceptor.spring.AttachCategoryInterceptor.invoke(AttachCategoryInterceptor.java:52)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at se.so4it.dam.server.category.interceptor.spring.AttachCategoryMetadataModelInterceptor.invoke(AttachCategoryMetadataModelInterceptor.java:36)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
        at $Proxy57.doExecuteCommand(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor86.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:100)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
        at $Proxy58.doExecuteCommand(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor86.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
        at se.so4it.dam.server.category.interceptor.spring.CategoryCommandExceptionInterceptor.invoke(CategoryCommandExceptionInterceptor.java:42)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at se.so4it.dam.server.category.interceptor.spring.CreateCategoryResponseInterceptor.invoke(CreateCategoryResponseInterceptor.java:32)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at se.so4it.dam.server.category.interceptor.spring.DetachCategoryInterceptor.invoke(DetachCategoryInterceptor.java:35)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at se.so4it.dam.server.category.interceptor.spring.SendCategoryResponseJmsInterceptor.invoke(SendCategoryResponseJmsInterceptor.java:46)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
        at $Proxy57.doExecuteCommand(Unknown Source)
        at se.so4it.dam.server.DigitalAssetManagementImpl.addCategory(DigitalAssetManagementImpl.java:350)
        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:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
        at se.so4it.dam.server.interceptors.LogCategoryRequestInterceptor.invoke(LogCategoryRequestInterceptor.java:40)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at se.so4it.dam.server.interceptors.LogRecordRequestInterceptor.invoke(LogRecordRequestInterceptor.java:45)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at se.so4it.dam.server.interceptors.LogRecordCollectionRequestInterceptor.invoke(LogRecordCollectionRequestInterceptor.java:43)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at se.so4it.commons.interceptor.LogMethodInterceptor.invoke(LogMethodInterceptor.java:43)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at se.so4it.commons.api.interceptor.CheckSessionInterceptor.invoke(CheckSessionInterceptor.java:59)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
        at $Proxy59.addCategory(Unknown Source)
        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:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
        at org.springframework.remoting.support.RemoteInvocationTraceInterceptor.invoke(RemoteInvocationTraceInterceptor.java:68)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
        at $Proxy59.addCategory(Unknown Source)
        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:585)
        at org.springframework.remoting.support.RemoteInvocation.invoke(RemoteInvocation.java:179)
        at org.springframework.remoting.support.DefaultRemoteInvocationExecutor.invoke(DefaultRemoteInvocationExecutor.java:33)
        at org.springframework.remoting.support.RemoteInvocationBasedExporter.invoke(RemoteInvocationBasedExporter.java:76)
        at org.springframework.remoting.rmi.RmiBasedExporter.invoke(RmiBasedExporter.java:72)
        at org.springframework.remoting.rmi.RmiInvocationWrapper.invoke(RmiInvocationWrapper.java:62)
        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:585)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
        at sun.rmi.transport.Transport$1.run(Transport.java:153)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
        at java.lang.Thread.run(Thread.java:595)
Caused by: net.sf.cglib.beans.BulkBeanException
        at se.so4it.dam.api.category.CategoryImplementation$$BulkBeanByCGLIB$$f1c8693.setPropertyValues(<generated>)
        at org.hibernate.bytecode.cglib.AccessOptimizerAdapter.setPropertyValues(AccessOptimizerAdapter.java:57)
        ... 119 more
Caused by: java.lang.NullPointerException
        at se.so4it.dam.api.category.CategoryImplementation.setParent(CategoryImplementation.java:137)
        ... 121 more
09:53:49,390 INFO  [LogCategoryRequestInterceptor] Executing category request 1b9f808235944c32350ae48b442471d5 took 4687
09:55:53,640 INFO  [LogCategoryRequestInterceptor] Executing category request dff12db4561a2a068af3c17299542593 took 118390



The NullPointerException is thrown when exiting
Code:
persistenceContext.afterLoad()
on the call to
Code:
Loader.doQueryAndInitializeNonLazyCollections


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 05, 2006 6:03 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Can you check if the code at
Code:
Caused by: java.lang.NullPointerException
        at se.so4it.dam.api.category.CategoryImplementation.setParent(CategoryImplementation.java:137)
        ... 121 more

doesnt have any errors? can you post the relevant code here as well ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 05, 2006 7:59 am 
Beginner
Beginner

Joined: Sun Feb 19, 2006 5:13 am
Posts: 22
Hi

Well it a bit hard to get a hold of the exact cause. What I found out is that Hibernate tries to set parent to null for the child Im trying to load. The error you saw in the last exception was due to that (I did some magic inside the setParent method).

Ok so why is parent null? , dont know since its not in the database. Now when I get past that is fail in the hashCode method of the parent since Im using guids for hashCode and equals. The same reason being that the instance has not been initiated with all properties only the id.

I don know I'll keep on investigating further later today. Why would it behave like this only on the 3:rd levele?


I'll be back :-)

Magnus


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 05, 2006 2:10 pm 
Beginner
Beginner

Joined: Sun Feb 19, 2006 5:13 am
Posts: 22
Hi

Ok I found the problem dont no why though :-)

Before I had the mapping file:

Code:
<hibernate-mapping>
    <class name="se.so4it.dam.api.category.CategoryImplementation" table="Category" dynamic-update="true">
        <cache usage="read-write"/>
        <meta attribute="implement-equals">true</meta>
        <id name="id" column="id" type="long" unsaved-value="null">
            <generator class="native"/>
        </id>
        <property name="guid" column="guid" type="string" unique="true"/>
        <property name="name" column="name" type="string"/>
        <property name="level" column="level" type="integer"/>
        <set name="categories" inverse="true" cascade="all" lazy="false">
            <cache usage="read-write"/>
            <key column="parentId"/>
            <one-to-many class="se.so4it.dam.api.category.CategoryImplementation"/>
        </set>
        <many-to-one name="parent" column="parentId" not-null="false" class="se.so4it.dam.api.category.CategoryImplementation" lazy="false"/>
        <set name="records" table="CategoryToRecord" cascade="none" lazy="false">
            <cache usage="read-write"/>
            <key column="categoryId"/>
            <many-to-many class="se.so4it.dam.api.record.RecordImplementation" column="recordId"/>
        </set>
    </class>
</hibernate-mapping>



I then changed to:

Code:
<hibernate-mapping>
    <class name="se.so4it.dam.api.category.CategoryImplementation" table="Category" dynamic-update="true">
        <meta attribute="implement-equals">true</meta>
        <id name="id" column="id" type="long" unsaved-value="null">
            <generator class="native"/>
        </id>
        <property name="guid" column="guid" type="string" unique="true"/>
        <property name="name" column="name" type="string"/>
        <property name="level" column="level" type="integer"/>
        <set name="categories" inverse="true" cascade="all" lazy="false">
            <cache usage="read-write"/>
            <key column="parentId"/>
            <one-to-many class="se.so4it.dam.api.category.CategoryImplementation"/>
        </set>
        <many-to-one name="parent" column="parentId" not-null="false" class="se.so4it.dam.api.category.CategoryImplementation" lazy="false"/>
        <set name="records" table="CategoryToRecord" cascade="none" lazy="false">
            <cache usage="read-write"/>
            <key column="categoryId"/>
            <many-to-many class="se.so4it.dam.api.record.RecordImplementation" column="recordId"/>
        </set>
    </class>
</hibernate-mapping>



So the change is that I excluded the
Code:
<cache usage="read-write"/>
for the
Code:
CategoryImplementation
mapping. Can anyone explaine the cache mapping here. Wan't this mean that the category being loaded want ever be in the cache while its associations will, or? Should there be a problem mapping both the owning instance and it associations?

Appriciate the help!

Magnus


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 4:18 pm 
Beginner
Beginner

Joined: Sun Feb 19, 2006 5:13 am
Posts: 22
Ok still havent solved this one.

Soi have a parent / child relationship with the following mapping
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="se.so4it.dam.api.category.CategoryImplementation" table="Category" dynamic-update="true">
        <cache usage="read-write"/>
        <id name="id" column="id" type="long" unsaved-value="null">
            <generator class="native"/>
        </id>
        <property name="guid" column="guid" type="string" unique="true" lazy="false"/>
        <property name="name" column="name" type="string" lazy="false"/>
        <property name="level" column="level" type="integer" lazy="false"/>
        <set name="categories" inverse="true" cascade="all" lazy="false">
            <cache usage="read-write"/>
            <key column="parentId"/>
            <one-to-many class="se.so4it.dam.api.category.CategoryImplementation"/>
        </set>
        <many-to-one name="parent" column="parentId" not-null="false" class="se.so4it.dam.api.category.CategoryImplementation" lazy="false"/>
        <set name="records" table="CategoryToRecord" cascade="none" lazy="false">
            <cache usage="read-write"/>
            <key column="categoryId"/>
            <many-to-many class="se.so4it.dam.api.record.RecordImplementation" column="recordId"/>
        </set>
    </class>
</hibernate-mapping>




On the server I recive a request from the client to get the parent / child structure. When loading, or as Hibernate call it dehydrating the object I get the following error when executing the method
Code:
org.hibernate.type.CollectionType.getCollection()



Code:
LazyInitializationException. Failed to evaluate expression for this object alternative view


I can se that it is the Set that fails being initiated. This leads in its turn that Hibernaet fails building the parent / child relationship.


I have to say Im all out of ides on this one so if anyone has a clue I would appriate it.

Magnus


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