-->
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.  [ 5 posts ] 
Author Message
 Post subject: PropertyAccessException on Parent/Child mapping
PostPosted: Tue Apr 18, 2006 5:14 pm 
Newbie

Joined: Tue Apr 18, 2006 5:03 pm
Posts: 5
I use Hibernate 3.1.3 with MySQL 5.0 and get a weird PropertyAccessException when i try to store my object.

Object
Is a class Projekt which can have subprojects. To prevent from unlimited nesting i throw an exception on the methods setParent(Projekt parent); and setSubProjekt(Projekt subProjekt); which causes Hibernate to fail in this case.

Mapping
Code:
       <many-to-one name="parent" column="Parent" not-null="false" />
        <set name="subProjekte" inverse="true" cascade="all,delete-orphan">
           <key column="Parent" not-null="false" />
           <one-to-many class="Projekt" />
        </set>


Stacktrace
Code:
Exception in thread "main" org.hibernate.PropertyAccessException: Exception occurred inside setter of ch.hftso.infox.model.Projekt.parent
   at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:65)
   at org.hibernate.tuple.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:330)
   at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:188)
   at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3232)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:253)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
   at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:502)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:494)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:490)
   at ch.hftso.infox.service.ProjektService.hinzufuegenProjekt(ProjektService.java:119)
   at ch.hftso.infox.testclient.TestClient.main(TestClient.java:121)
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:585)
   at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
   ... 15 more
Caused by: java.lang.Exception: Projekt mit Subprojekten muss Root sein!
   at ch.hftso.infox.model.Projekt.setParent(Projekt.java:120)
   ... 20 more


What is going wrong here?!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 12:27 pm 
Newbie

Joined: Tue Apr 18, 2006 5:03 pm
Posts: 5
Could it be a mapping problem? Thought that throwing Exceptions should be no problem in Hibernate POJO's, isn't it?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 5:12 pm 
Newbie

Joined: Wed Aug 18, 2004 8:44 am
Posts: 12
Please put here the code for the setter of the classes


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 6:41 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 2:26 pm
Posts: 28
roele wrote:
Could it be a mapping problem? Thought that throwing Exceptions should be no problem in Hibernate POJO's, isn't it?


no, that's not a good idea at all. if you throw an exception, hibernate won't be able to set the value and hence won't be able to save the class.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 5:53 am 
Newbie

Joined: Tue Apr 18, 2006 5:03 pm
Posts: 5
Here is the method which causes the problem...

Code:

   public void subProjektHinzufuegen(Projekt p) throws Exception {
      if (parent==null){
        try{
           p.setParent(this);
           subProjekte.add(p);
         } catch (Exception e){
         throw e;
         }
      } else {
         throw new Exception("Subprojekt kann keine weiteren Subprojekte enthalten!");   
      }
   }



@Imiranda: Then i guess such things should be handled outside of a POJO?


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