Take the 2-minute tour ×

I'd like to know if it's possible to delete parent objects in a bidirectional 1:N association without a cascade delete. According to


...in a unidirectional relationship the parent end gets mapped with a 'save-update' and the child end with a 'none'. I've tried these settings for the bidirectional relationship, but not very surprisingly it didn't work. Specifically:

class Personnel {

static hasMany = [projectlead:Project, projectmanager:Project]

static mappedBy = [projectlead:'leaddeveloper', projectmanager:'projectmanager']

static mapping = {
    projectlead     cascade:'save-update'
    projectmanager  cascade:'save-update'

And here's the project class:

class Project {
static belongsTo = [leaddeveloper:Personnel, projectmanager:Personnel]

static mapping = {
    leaddeveloper   cascade:'none'
    projectmanager  cascade:'none'

I'd rather not redesign my application (by removing the "belongsTo" from the Project class) if there's a solution to this: the navigational access from both ends is very convenient and I don't have too much instances on the project end.

Also, if there's a way to implement this, it would be interesting to know, what happens with those active mappings afterwards, can I set them (or will they be set) to "null" for instance?

Appreciate any inputs on this matter.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

By reading your question, I think that you want to delete "Personnel" object but leaving his "projects" untouched. Sadly, this can't be done with your current implementation. A "belongsTo" relationship means that every child object must has a Parent object. If you delete the Parent, the orphan will be deleted as well.

Another option that you could try without modifying too much the design is "marking as deleted". Add a "deleted" field in Personal, and in case you want to delete someone, just mark him as deleted. This will help you keep the historical data of projects, even after the project manager left.

share|improve this answer
Hi Hoang, many thanks for your suggestion... I think that's how I'm gonna implement this! –  sphere Apr 19 '11 at 13:41

Your Answer


