Figured it out... It had to do with me setting the inverse='true' on the
Document side of the relationship.  By moving inverse='true' to the
'documents' Set under class 'Project', it allowed the Document instance to
manage the relationship.   Great explanation of it here:
http://simoes.org/docs/hibernate-2.1/155.html



kla wrote:
> 
> I have a optional one to many relationship between a project and a
> document.  I have tied these records together using a 3rd an associative
> table:
> project : project_id
> document : document_id
> project_document : project_document_id, project_id, document_id
> 
> I'm trying to delete a document but am getting constraint errors.  It is
> not cascading as I would hope it would.  Here are my mappings:
> 
>     <class name="Document" table="document">
>         <id name="id" column="id" unsaved-value="null">
>             <generator class="identity"/>
>         </id>
>         
>         ...
>         
>         <join table="document_project" inverse="true" optional="true" >
>             <key column="document_id"/>
>             <many-to-one name="project" column="project_id"
> not-null="true" cascade="all" /> 
>         </join>
>         
>        
>     </class>
> 
> 
>     <class name="Project" table="project">
>         <id name="id" column="id" unsaved-value="null">
>             <generator class="identity"/>
>         </id>
> 
>         ...
> 
>         <set name="documents" table="document_project" >
>             <key column="project_id"/>
>             <many-to-many column="document_id" unique="true"
> class="Document" />
>         </set>
>     </class>
>     
> 
> However, like I said, when I call 
> docManager.removeDocument(documentId); I get a constraint error.  I've
> been a way from Hibernate a while.  I'm sure its something simple but I
> can't figure it out.   Should'nt the cascade="all" on the join-table
> automatically delete 'document_project' dependent records 1st?
> 
> Any help would be appreciated.
> Thanks,
> Mike
> 

-- 
View this message in context: 
http://www.nabble.com/Hibernate-cascade-delete-not-working-tf4319665s2369.html#a12316808
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to