-->
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.  [ 4 posts ] 
Author Message
 Post subject: Exception occurred inside setter of...
PostPosted: Tue Feb 10, 2004 2:38 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 10:39 pm
Posts: 44
I am getting a "Exception occurred inside setter of..." an attribute at session.flush() eventhough this attribute is no where being set in my code. Root cause is a NullPointerException.

This is the full exception:
Code:
Exception occurred inside setter of com.forisent.framework.itemOrganizer.store.entity.OneToManyRelationship.element

net.sf.hibernate.PropertyAccessException: Exception occurred inside setter of com.forisent.framework.itemOrganizer.store.entity.OneToManyRelationship.element
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:49)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:225)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:869)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:817)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:740)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:717)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1322)
at com.forisent.framework.itemOrganizer.store.factory.PersistanceManager.persist(PersistanceManager.java:65)
at com.forisent.framework.tests.itemOrganizer.store.factory.PersistanceManagerTest.testPersistOneRelationship(PersistanceManagerTest.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.apache.cactus.server.runner.ServletTestRunner.run(ServletTestRunner.java:313)
at org.apache.cactus.server.runner.ServletTestRunner.doGet_aroundBody0(ServletTestRunner.java:209)
at org.apache.cactus.server.runner.ServletTestRunner.doGet_aroundBody1$advice(ServletTestRunner.java:151)
at org.apache.cactus.server.runner.ServletTestRunner.doGet(ServletTestRunner.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:228)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.jboss.web.tomcat.tc4.statistics.ContainerStatsValve.invoke(ContainerStatsValve.java:76)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:65)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:577)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:534)
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 net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:38)
... 71 more

Caused by: java.lang.NullPointerException
at com.forisent.framework.itemOrganizer.store.ElementReference.<init>(ElementReference.java:17)
at com.forisent.framework.itemOrganizer.store.entity.OneToManyRelationship.setElement(OneToManyRelationship.java:214)
... 76 more


This is the JUnit test that executes:
Code:
Relationship element = (Relationship) new OneToManyRelationship("Product Category", "Category");
         
manager.persist(element);


All the manager.persiste() method does is:
Code:
public void persist(Object obj) throws HibernateException{
      Session session = _SessionFactory.openSession();   
      log.info("Persisting object: " + obj.getClass().toString());
      session.saveOrUpdate(obj);   
      session.flush();
      log.info("Done Saving!");
      session.close();
   }



Here is are the getter and setter methods of element in my class OneToManyRelationship code:
Code:

    /**
     * @hibernate.many-to-one
     * class="com.forisent.framework.itemOrganizer.store.ElementReference"
     * column="elementReferenceID"
     * not-null="true"
     * cascade="all"
     */
   private ElementReference getElement(){
      return this.element;
   }

   ....

   public void setElement(Identifiable element)
throws ElementTypeException {
       //Set just one element since this is OneToMany relationship
       this.element = new ElementReference(element);
    }
   


The strange part is, setElement is called nowhere in my code. So, I am assuming that hibernate calls this setter during persisting this class. What happens is that setElement is called with a null element value and the wrapper class ElementReference throws a null pointer exception in its construtor since the attributes of Identifiable are called in the ElementReference constructor.

First, am I correct and Two, what can I do about it?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 2:58 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
What identfier are you using for your ElementReference class?
Show us your mappings...


Top
 Profile  
 
 Post subject: Re: Exception occurred inside setter of...
PostPosted: Tue Feb 10, 2004 5:48 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
single wrote:
The strange part is, setElement is called nowhere in my code. So, I am assuming that hibernate calls this setter during persisting this class. What happens is that setElement is called with a null element value and the wrapper class ElementReference throws a null pointer exception in its construtor since the attributes of Identifiable are called in the ElementReference constructor.

First, am I correct and Two, what can I do about it?

Hibernate call setElement, it needs it to populate your objects.
your setters should be Exception friendly.

You can create a private setter you'll map and use a public setter for you data check.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 2:16 pm 
Beginner
Beginner

Joined: Thu Feb 05, 2004 10:39 pm
Posts: 44
ok, thanks to both of you. I reread the FAQ and my problem was that my getter was returning the type ElementReference and my setter was taking in a differet object type.


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