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>
StacktraceCode:
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?!