I have a one-to-one mapping based on a foreign key
Code:
CONTENT {
ID NUMBER(16),
XML_CONTENT BLOB
}
ARTICLE {
ID NUMBER(16)
NAME VARCHAR2,
ID_CONTENT,
FOREIGN KEY(ID_CONTENT) REFERENCES CONTENT
}
My mappings are:
In Content:
Code:
<one-to-one name="article" class="de.ems.cms.beans.Article"
property-ref="content" constrained="true"/>
In Article:
Code:
<many-to-one name="content" class="de.ems.cms.beans.Content"
column="ID_CONTENT" unique="true" cascade="all"/>
I create an Article (a) and a Content(c), I use
Code:
a.setContent(c);
and when I try to save I get the following error.
Shouldn't the Content be save automatically because of cascade="all"?
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: net.sf.hibernate.persister.EntityPersister.article
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: net.sf.hibernate.persister.EntityPersister.article
at net.sf.hibernate.impl.SessionImpl.checkNullability(SessionImpl.java:1206)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:871)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:815)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:738)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:715)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1317)
at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:841)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:815)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:738)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:715)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1317)
........................
Thanks,
Daniel